+ 1
Is it Advisable to add different states to different components in React
Am new to react.. so right now am creating a project.. So my question is now Is it Advisable to add different states to different components in React... Why am asking these is because normally in react, we usually have a kind of global components that renders the whole jsx file to the don and at most times that component usually hold a state variable... So while creating another component, is it still good to create another state rather than using props.. đ˘đ˘
1 Answer
+ 4
E-lotzđłđŹ The heart of most of the React component is its âstateâ, an object that determines how that component renders & behaves. In other words, âstateâ is what allows you to create components that are dynamic and interactive.
Adding state to every component is not useful if you don't want that component to be dynamic and interactive.
Futher, if you change state of the component, then it triggers a re-render of the component.
Causing too many unnecessary re-renders might slow down your app.
Lastly, if the component logic can be managed inside of it through state, then I don't think there is a need to use props.