How can a Tab2 know, during render, if it's the currently selected tab?
I want to do this to change the content or style of the tab title (e.g., the selected tab's title is italicized).
I'd prefer not to use onChange and manage the Tab2 state, as Tab2 already knows its own state.
<Tabs2 id="TabPane">
<Tab2
id="TabFirst"
panel={SomePanel}
>
<Text>
{ isCurrentTabId("TabFirst")
? "I am selected!"
: "I'm not selected"}
</Text>
</Tab2>
<Tab2 id="TabSecond"/>
</Tabs2>
const isCurrentTabId = (tabId) => { ??? };
What code goes where the "???" is?
Thanks!
I think you need to rethink your approach.
The parent Component should know which tab is selected and not the tab itself.
Lets say the tab itself will know if it selected via an
onClick
event or whatever other approach, OK then, you render the style like you wanted.Now, what happens when i click
Tab5
? it will know that it is the selected tab, but what about the first tab? who will notify it that its not selected anymore?I think it's the parent of all Tabs responsibility to manage who is the selected Tab, and the parent can pass down a prop for each tab, like
isSelected
for example to notify it if it selected or not.A small example: