javascriptreactjstypescriptnext.jsrsuite

How to remove the chat value in array tab in react


tabs: [ '/home', '/about', '/chat' ];

<ResponsiveNav ppearance="subtle" justified
                  removable
                  moreText={<Icon icon="more" />}
                  moreProps={{ noCaret: true }}
                  activeKey={activePage['link']}
                  onSelect={onSelectTab}
                  onItemRemove={eventKey => {
                    console.log(eventKey)
                  }}>
                  {tabs.map(tab => {
                    const menu = menus.find(a => a.link === tab);
                    return <ResponsiveNav.Item key={menu ?.key} eventKey={tab}> {menu ?.label}</ResponsiveNav.Item>
                  })}
                </ResponsiveNav>

How to remove the value '/chat' from the tabs. What I tried is I added this on the onItemRemove

  const tabList = [...tabs]
                  tabList.splice(
                    tabList.map(item => item).indexOf(eventKey),
                    1
                  );

                  tabs.push(...tabList)

                  router.push(tabList[0] ? tabList[0] : '/')

But It doesn't work. Every time I click it keep pushing a value.


Solution

  • you could use splice

    const sample = ['/home', '/about', '/chat']
    const index = sample.indexOf('/chat') // get index here
    
    sample.splice(index,1) // delete one element at (index)
    console.log(sample)