Design comparison
Solution retrospective
Hi all! Nothing special really... working on my React course and found this little project to be good practice for the useRef hook. I've taken some creative liberty on the original design just for funsies.
Community feedback
- @adityaphasuPosted over 1 year ago
Hi! The design looks epic!✨
For the past 10 mins I was trying to see why the website was not showing me the section with the text and I was like lemme try out other browsers and it showed out perfectly in those... I thought my chrome was broken but it seems like you named the section
advert-container
and my adblocker extension thought it was some kind of ad and deleted it 😭Might wanna change the section's classname to something like content container or something along those lines in case others also have some sort of adblocker on hahahaha 😆
I really like the usage of
useRef()
hook! though would like to ask what would be the better hook to useuseState
oruseRef
for inputs (I'm really conflicted on these since recently seeing lots of articles where some say useState is better as you'd want to have those as controlled components and the docs also seems to recommend that over useRef but some say that you dont want complete rerenders of simple values of inputs hence useRef) would love to hear your thoughts on this! 🙂Marked as helpful0@EdwinSchPosted over 1 year ago@adityaphasu Hi Boots! Wow, that's actually very good te know... had no idea this would cause issues with Ad Blockers. Although it kinda makes sense now I'm thinking about it haha. I will definitely edit the code, thanks!
The
useRef
hook is a pretty confusing concept compared touseState
. Why use it in the first place? Well,useRef
is purely for accessing DOM nodes directly, thus bypassing the virtual DOM which React generates (and is used by theuseState
hook). So this is basically the React version of:document.querySelector()
in vanilla JS. Another big difference is thatuseRef
does not re-render anything. So your mentioned argument on not re-rendering simple values is very valid. This is better for the app performance.That being said; because React makes use of the virtual DOM principle
useState
is always the preferred way of doing things. And this is actually best-practice in a lot of companies.useRef
should only be used if you can not achieve your goal withuseState
. A good example of this for instance is getting window or container dimensions from the DOM, here you will need to access the DOM (nodes) directly.1@adityaphasuPosted over 1 year ago@EdwinSch omg thanks for the reply! The reason I asked about this was because last night I came across this video by webdev simplified where he was talking about this and people in the comments were arguing about the same thing I asked ...went on to search more about this just to find myself more conflicted and it seems to happen you did a challenge based on this and I couldn't help it but ask haha! Thank you so much for clarifying!😊
0@EdwinSchPosted over 1 year ago@adityaphasu No problem. This is actually why Svelte is gaining massive popularity, it doesn't make use of a virtual DOM but manipulates the actual DOM instead. So Svelte acts more like vanilla JS (including the syntax). Could argue it's one big useRef framework haha. It's a whole discussion on itself, I've already fallen into that rabbit hole... :P
All fun, but in the end the user doesn't give a crap about how we build it. It just has to work properly.
1 - @samuerikcoderPosted over 1 year ago
OMG IT'S SO BEAUTIFUL
1
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