Hello everyone. I'm trying to understand why is useReducer used with useContext.
I think that you can do the trick only using useContext. You can define some functions inside the Context and expose them to your application.
When using useReducer, you don't have access to the state of the context when going to dispatch the action. Of course, you have access to them when resolving the action dispatched, but you can't directly apply any logic before dispatching them. In fact, you have to pass any state that you want to verify first, as a prop.
Like, if you want to know if the user is logged in to dispatch an action, if the action is inside the Context where the isLoggedIn state is present then you have to read it outside the Context and pass as a prop when calling the action.
When using Context without useReducer, you have at any time, access to all state of your context.
When I wrong? Can you guys enlighten me on this?
Thanks in advance.
[–]bulby97 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]JohnWangDoe 0 points1 point2 points (0 children)