How to lazy-load tabs on antd?
Asked Answered
D

2

5

I am using antd tabs and I have 2 tabs on my page. Both load at the same time but I want only the first tab to load on mount and onchange of tab the other tab should be rendered. I am unable to achieve this functionality.

Is there a way to resolve this issue?

Dentalium answered 19/7, 2018 at 22:12 Comment(0)
T
3

According to the documentation, the default for the forceRender prop on the Tabs.TabPane component in your code should be false.

The prop is used to: Forced render of content in tabs, not lazy render after clicking on tabs:

https://ant.design/components/tabs/

On what basis are you assessing that the content is not lazy rendered? Perhaps you can share some code.

Beyond this, you may want to handle more complex rendering within your component tabs using state.

I hope this helps.

Tchad answered 22/7, 2018 at 7:24 Comment(1)
I want to render content of the second tab based on the data I get from api call in the first tab. How can this be done?Punke
T
3

Try destroyInactiveTabPane prop on Tabs.

const App = () => {
  return (
    <Tabs
      items={items}
      destroyInactiveTabPane={true} // add this prop
    />
  );
};
Thayne answered 13/4, 2023 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.