For ReactJS, how is the change from using Container components and Presentation components to using Hooks?

Viewed 199

In the past, in ReactJS, one way was to divide our components into Container components and Presentational components, and even Dan Abramov wrote a note about it not any more the case if we can use Hooks now.

How should it be done now — how does Hooks solve the problem?

The question is more like: even with function components that can have states, should we still design our app to have container components that have states, and have presentational components that strictly do not have state, and therefore is like "pure function" to take props and present data. Or should we not care and use states in every component we have?

1 Answers

With hooks, you can make functional components stateful here is an example

Const Component =()=>{
 Const [count, setCount]=useState(0);
 Return(
    <Button

      onClick={()=>setCount(count+1)}      
     >{count}</Button>)}

** and if you compare both class-based components and functional components you will see how hooks make it less code and cleaner to read and understand hope I explained well! **

Related