Is this how Props work in React...?
Max just blew my mind and I'm not sure if that's an inexperience thing my end, or if he's doing something wonky..
He's created a button with an onClick event in TabButton.jsx, that function takes children and onSelect as props, there's then a function in app.jsx, handleSelect that displays the output, and the component is in app.jsx as <TabButton onSelect={handleSelect}>Components</TabButton>
Am I going crazy here, or is this standard practise? lol - I removed some of the code in App.JSX as it wasn't relevant to the question
TabButton
App.jsx
12 Replies

your component receives an object with the properties
you're just unpacking the object properties into variables
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring#object_destructuring
look for this title:
Unpacking properties from objects passed as a function parameterthat's exactly what you're doing there
ahhh.. ok yeah, I get it
felt unnatural reading it at first but it kinda makes sense now
it makes sense, if you need it as variables
however, it can be a pain if you receive multiple attributes from the component
for just a few (1-4), it may be a lot easier to use this
but for more, it becomes cumbersome and just use the
props
however, the type checker may be more happy with the unpacked propertiesThanks @ἔρως 😎
just do what feels more natural
you're welcome
this is one of the cases where you can say "it's just javascript"
I think him using onSelect is where my confusion is coming from. Makes more sense being onClick lol
but I can see why he's doing it
basically, it's being called "onSelect" because it's executed when the tab is selected
which is implemented by adding a
<button>
with a click event
and when's the tab is selected? when you click the button
but that's mixing implementation details
from the user side, it's just an event that runs when you select the tabGotcha!
makes more sense now?
It does, thanks again 😄
you're welcome