react-tabs icon indicating copy to clipboard operation
react-tabs copied to clipboard

Cannot render tabpanel as component

Open nguyenhuutinh opened this issue 7 years ago • 3 comments

I have dynamic tabpanel content. So I need to create component to call API. render () { return ( < TabPanel className="content__products" > ...

But it cannot render. error: "There should be an equal number of 'Tabs' and 'TabPanels'.Received 3 'Tabs' and 0 'TabPanels'."

Do you know why?

nguyenhuutinh avatar May 07 '18 14:05 nguyenhuutinh

While I can't completely make out what you're trying to do, I suspect you're trying to wrap your <TabPanel>s in a different component within <Tabs>. Unfortunately, this is not supported. You'll need to implement your tabs in such a way that you're always passing an equal amount of <Tab>s and <TabPanel>s to the component, with the following constraints:

  • <Tab>s need to be direct descendants (children) of <TabList>
  • <TabPanel>s need to be direct descendants (children) of <Tabs> (so they are siblings of <TabList>)

joepvl avatar May 30 '18 03:05 joepvl

@joepvl just checking in, are these constraints still true and is there any chance that supporting containers around Tabs is on the roadmap?

anjalikk14 avatar Sep 10 '20 05:09 anjalikk14

The constraints still hold, and there are no plans to change that. However, you can create a custom TabPanel if you want, using the method described at the very end of the README: https://github.com/reactjs/react-tabs#custom-components.

joepvl avatar Sep 11 '20 10:09 joepvl