There are two tabs in my code and on click of the second tab I need to show one message but I'm not knowing how to know when the second tab is selected.
The problem is the selectedIndex is not getting changed at all and the message which I wanted to show is not coming up.
const [selectedIndex, setSelectedIndex] = useState(1);
<Tabs selectedIndex={selectedIndex} onSelect={(index) => setSelectedIndex(index)} />
<TabList>
<Tab>One</Tab>
<Tab>Second</Tab>
</TabList>
<TabsPanel>content</TabsPanel>
<TabsPanel>content</TabsPanel>
</Tabs>
if (selectedIndex == 2) {
//Show something
//Need this msg outside the tabs
}
I have tried this and as per the react-tabs documentation this should work but it is actually not working in my case. Please suggest any alternative for onSelect or atleast show how to change the selectedIndex while in the second tab.