how to get select tab in lib tabs

Viewed 76

I want to get the selected tab

<Tabs defaultActiveKey="1" >
    <Tabs.TabPane tab="SITES1" key="1">
    </Tabs.TabPane>
    <Tabs.TabPane tab="SITES2" key="2">
        Content of Tab Pane 2
    </Tabs.TabPane>
    <Tabs.TabPane tab="SITES3" key="3">
        Content of Tab Pane 3
    </Tabs.TabPane>
<Tabs />

Based on the selected tab I want to call apis.

1 Answers

you need to have an onChange function there:

const [active,setActive]=useState("1");

    function callback(key) {
          console.log(key);
          setActive(key)
        }  
        
          <Tabs defaultActiveKey={active} onChange={callback}>
            <Tabs.TabPane tab="SITES1" key="1">
            </Tabs.TabPane>
            <Tabs.TabPane tab="SITES2" key="2">
                Content of Tab Pane 2
            </Tabs.TabPane>
            <Tabs.TabPane tab="SITES3" key="3">
                Content of Tab Pane 3
            </Tabs.TabPane>
        <Tabs />
Related