What I'm about to show you is really pretty basic. So Code Gurus out there can feel free to breeze on by this article. But I've rarely seen this ...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
This approach can be improved by using data attributes in the target element handled by the click event. For example
Data attributes can be applied to any element and are guaranteed never to interfere with native functionality provided by native attributes. Note that child tags on the element will mean that you may have to traverse up the parent tree back to the intended target before you can access the attributes. But itβs nice because you can have as many attributes as you need without trying to figure out what native attribute to use.
Great article!
Great point! And yeah, I should've touched on data attributes as well. Thank you!
Just did a quick cross-read (bookmarked for later fully-comprehensive reading) and I'm wondering if Styled-Components wouldn't apply better to this use-case (so you just pass the color as prop and you don't need to generate all classNames beforehand/through a process) π
That's basically what I covered under the "Wrapper Components" section.
Amazing!
See, that's why I need to read it calmly afterwards ππ cross-reading is never enough π
LOL. To be fair, I didn't specifically put it in the context of styled components. But it's basically the same concept.
haha yes, I've seen it briefly π ty!
Just did a quick cross-read (bookmarked for later fully-comprehensive reading) and I'm wondering if Styled-Components wouldn't apply better to this use-case (so you just pass the color as prop and you don't need to generate all classNames beforehand/through a process) π
There's a whole section on "Wrapper Components"...
Wow, this article is awesome! The way you explain the technique for extracting bits of data from JSX elements is on point. I'm pumped to see more content like this from you in the future! Keep up the great work!
Thank you!
You could also use data as well as data attributes. I mostly use data attributes for CSS.
For this specific case it's also possible to use
useMemo
.