Design comparison
Solution retrospective
I used useEffect to call a function on change of className of a project I did not so while back and also used it here. do you guys recommend this
Community feedback
- @joshua-mo-143Posted almost 2 years ago
Hey man, this looks pretty good. Might need a bit of UI tweaking on mobile but otherwise, at a base level it's decent.
I would personally avoid trying to use useEffect for state changes because you can end up in an infinite render loop if you're not careful re: dependencies. You could just instead use
onClick={handleChange}
or something similar and then put the change code in handleChange. Theoretically speaking, if I were to do this I'd probably just add or delete the string to an array of strings on click and then filter the results based on whether or not the word exists within the string of categories.I'd highly recommend splitting your main page into components as it's a bit confusing and would help with enforcing single-role responsibilities of components. This is the exact kind of thing that React is extremely good at and it'll help you much later on. If you're worried about passing props, you can just simply pass state setters and getters as props into child components.
You don't need to set any external data to a state. The data is automatically immutable unless you make an actual file change and it doesn't appear that you make any direct changes to the data.
Hope this helps!
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord