@kem522
Posted
Hi Jome, this is great!
Your use of hooks, especially useRef which is a bit of a confusing concept in my opinion, are excellent.
Here are a couple of suggestions:
-
This is mostly personal preference, but in your Main.js you save the result of stats.map to a variable and then use that in the body of the component whereas I think most developers that I've worked with would expect to see that stats.map directly in the body of the component. I think it is every so slightly more performant as it saves having to use that extra bit of memory for the variable.
-
In Nav.js you set an eventListener in the component but I would do this in your useEffect hook and then use that same hook to clean it up. If you don't clean up listeners like this they can stick around when your component gets destroyed eating up memory and could get set again and again if your component gets re-rendered. Here is an article that explains a little more about that.
I would highly recommend looking into styled components for your CSS next time you use React. They work really well together and are a lot of fun to use!
Keep it up!
@jomefavourite
Posted
Thanks @kem522 for the suggestions.
I'll try setting the event listener into useEffect and cleaning it up.
I just started looking into styled components yesterday, it seems very promising.