Home > Software engineering >  can we only use useReducer for global State
can we only use useReducer for global State

Time:05-27

like i was thinking. can we have a Reducer which we import and use 'useReducer' hook to dispatch actions on to it.instead of context api

I'm really new to react so sorry if this is stupid question

CodePudding user response:

You can useReducer at the root component and keep inside it global state, but the problem you will encounter is you will need to pass that state to different components, and for that you might need to use prop drilling (e.g. forwarding props to components located deep in component hierarchy), which maybe inconvenient. And for that you may use useContext to avoid that issue.

CodePudding user response:

well it depend on your objective.

I believe that the following article will answer your question

Article

  • Related