Closed mikeyhogarth closed 5 years ago
Thanks for the review mate, I'm going to go through it line by line, but it looks like I need to read up on redux to handle the process of shuffling around actions as I accept totally your argument around the additional logout functionality example.
This "state maze" seems very much like a common issue with react apps, at least as I've been designing this one so I'm glad there's an accepted solution! As with react I'm going to go read the docs first...
Did a quick code review, the advice here please feel free to either take or ditch, i had 10 mins spare and thought I'd take a look. Some comments are in-line, but in addition;
The good
The bad
Context
API. The way you've done it here won't scale - with multiple contexts appearing and providing to different parts of the component tree, one day it'll become unwieldy.Your State management solution
You are spreading business logic (particularly, state-update logic) throughout your components rather than centralising it. If/when you check out using dispatch/reducers (whether through the built in hooks or through redux/flux/mobx) what you'll see is;
It means that when you are wondering about the logic of your app, say, logging someone in/out, you don't need to worry about which component that happens in because you know it's just going to be in a single reducer somewhere.
With your current setup, consider this: Imagine you wanted another logout button somewhere, or you wanted a certain action to force a logout. As you have it now, you'd need to extract that logic somewhere and re-implement your context stuff in the new place.
Using reducer/dispatch, you just dispatch a logout action.