Closed lucas-viewup closed 2 years ago
From the code you posted, I can't easily make out what you're trying to do, or in what way it isn't working. Creating an example on e.g. https://codesandbox.io that shows what you're running into would help us and others help you.
That said, you're right, that component wrapper will cause an issue — the short of it is that <Tabs>
won't be able to find the <TabPanel>
s in its descendants because their rendering is deferred to a different component. Unfortunately, the why and how of this behaviour are kind of integral to how react-tabs
works right now, so you're not likely to see support for your case soon.
Regardless, I suggest questioning your assumption with respect to why you're experiencing a delay when switching tabs. From what I'm reading, I think you're suspecting unnecessary updates/rerendering to be the culprit, which is probably a good guess, but without using any dev tools to find out where exactly the delay is coming from it's hard to figure out where it's happening. I also don't think wrapping your panel rendering within a separate component, had it been an option in this case, would have improved perf. The rendering would still need to happen — simply wrapping the components wouldn't prevent that. In fact, you'd add another layer of rendering, so technically it would be more work for the renderer! But it wouldn't make a practical difference.
Thanks for feedback and hints, @joepvl! As soon as I get some time, I will create an sample https://codesandbox.io. I will do some tests in that platform and see if i will experience the same issues I'm having in a real application and share with you. If we could do, let's do it better then!
Regards,
@lucas-viewup any updates on this?
Hello, I'm using the react-tabs and is working well but I feel a little delay on switching the tabs, I suppose that is because the size of the render of my component:
In a attempt to optimize the performance of this, I tried to split in two components, a component to render the TabList with the Tabs and a component to render the TabPanels:
The fact is that the second component didn't work, I guess is because of the wrapper the functional component creates in the React DOM. I had this same problem with the tabs of material-ui either. Maybe some key-value prop could solve this issue? Here is some example:
<Tab tabId="my-id" />
...<TabPanel tabId="my-id" />