REACT global state!

Hey FCC Campers, someone can explain me what’s exactly the global state, and how we use ! am not understanding ! i searched in the web but didn’t find the right explanation to do this MCQ !! Thank you in advance !!

The word “global” is the antonym to the word “local”.

When you have a component, e.g. in React, this component can have a local state, e.g. a button to toggle a navigation. Because other components don’t need to know about this state, you want to make this local. E.g. the footer of a site doesn’t care if the header navigation is collapsed or not.

Then there is state that should be global, meaning many components need to know the state. Can you come up with an example?

1 Like

I would say that there isn’t a “global” state in a true sense in React. The closest would be using the state in the root component and passing it down to everywhere you use it. You could also do something with context to approximate it.

But that question is about redux, not just React - every one of those answers refers to redux. The middle answer is the closest to being correct, even if it’s a little incomplete. You would call connect with your mapStateToProps and the you’d wrap your component in the HOC returned by that - that would get you access to the redux store which is effectively a global state.