Design comparison
Solution retrospective
I've learned a lot from this challenge and I'm kind of proud of doing it on my own. I've used React and React Router for building this and I'd love your opinion on the approach of my code. Thanks in advance!
Community feedback
- @fazzaamiarsoPosted almost 2 years ago
Hello Guilherme! Nice Work!
I have a quick improvements for you.
You should put side effects such as interacting with DOM outside a component rendering. For example, in your
App.js
, you manipulate DOM to update a class in component's rendering phase. That can lead to an unpredictable behaviour.A better way is either do it in a function or
useEffect
.const [darkTheme, setDarkTheme] = React.useState(false); ✅ Effects run when `darkTheme` changes React.useEffect(() => { if (darkTheme) { document.body.classList.add("darkTheme"); } else { document.body.classList.remove("darkTheme"); } }, [ darkTheme ])
I hope it helps! Cheers!
Marked as helpful0@gguilhermelopesPosted almost 2 years ago@fazzaamiarso nice! Thanks for the tip!
0
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