Is it Advisable to add different states to different components in React | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.. 😢😢

31st Dec 2020, 4:23 AM
Larsun
Larsun - avatar
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.
31st Dec 2020, 4:51 AM
Art1mis