question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tabs and CustomTabPane

See original GitHub issue

Hello,

Sorry I’m not a chinese speaking user and sorry this is not really an issue. I’d like to know if it is possible to pass a custom TabPane to Tabs instead of a TabPane component.

Exemple:

Classic:

import {Tabs} from 'antd';
const TabPane = Tabs.TabPane;

    <Tabs defaultActiveKey='1' animated={false}>
        <TabPane key={'1'} tab={<h4>One title</h4>}>
                {some components that use props my_prop}
        </TabPane>
        <TabPane key={'2'} tab={<h4>Another title</h4>}>
                {some components that use props my_prop}
        </TabPane>
    </Tabs>;

What I try to achieve:


import {Tabs} from 'antd';
const TabPane = Tabs.TabPane;

     const CustomTabPane = ({key, my_prop, title}) =>
        <TabPane key={key} tab={<h4>{title}</h4>}>
                {some components that use props my_prop}
        </TabPane>;

    <Tabs defaultActiveKey='1' animated={false}>
        <CustomTabPane key={'1'} my_prop={a} title="One title"/>
        <CustomTabPane key={'2'} my_prop={b} title="Another Title"/>
    </Tabs>;

The second Option does not display a thing. What should I add for using a custom component for Tabs to be able to render my CustomTabPane?

Thank you,

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:25 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
GuillaumeCiscocommented, Mar 7, 2017

@paranoidjk Doing what you’re suggesting is not a good practice. React is about components and thinking with components. Not using interpolation hack everywhere… Also it will break rendering performance optimization. With this code, you cannot use shouldComponentUpdate and avoid some rendering. It’s a huge no no.

Last thing, using high ordering component is very used in real life. You can for example write:

import {Tabs} from 'antd';
const TabPane = Tabs.TabPane;

const NestedComponent1 = ({my_prop}) => <div>1 {my_prop}</div>
const NestedComponent2 = ({my_prop}) => <div>2 {my_prop}</div>

const HOC = (Component) =>
     const CustomTabPane = ({key, my_prop, title}) =>
        <TabPane key={key} tab={<h4>{title}</h4>}>
                <Component my_prop={my_prop} />
        </TabPane>;

     return CustomTabPane;

const TabPane1 = HOC(NestedComponent1);
const TabPane2 = HOC(NestedComponent2);

ReactDOM.render(
    <Tabs defaultActiveKey='1' animated={false}>
        <TabPane1 key={'1'} my_prop={a} title="One title"/>
        <TabPane2 key={'2'} my_prop={b} title="Another Title"/>
    </Tabs>
, mountNode);

It allows us to completely control each component and its render cycle. It is easier to read and to understand. Using composition allow to change one of the component in the chain list and using the other. Overriding only the component we want. For example in a case of the html tag table, we know we can have a tbody, tr, td. If we define a component for each of these html tag based on our needs and use them. Further in the project we want to use them but with a different implementations of tr for example. High ordering component composition allow you to only change this particular component thanks to … composition. Code will look this way const CustomTable = TableHOC(TableBodyHOC(MyNewTrHOC(Td))), and then pass your props to CustomTable like you normally do. This is extremely powerful and reliable.

I don’t know what’s going on with the current implementation of antd and customs TabPane not being recognized by Tabs… Not even a single error message is thrown… We can see the same use case with Material UI and Table component, it expects Tbody and Thead components. But you can use a custom component by adding it a muiName for making it works… I was looking for this kind of answer posting this issue.

I don’t have the correct rights to reopen this issue. But one thing sure, this is not solved yet…

1reaction
paranoidjkcommented, Mar 7, 2017

@GuillaumeCisco you just need to do this, pass down all restProps

const HOC = (Component) => {
     const CustomTabPane = ({key, my_prop, title, ...restProps}) =>
        <TabPane key={key} tab={<h4>{title}</h4>} {...restProps}>
                <Component my_prop={my_prop} />
        </TabPane>;

     return CustomTabPane;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Tabs - Ant Design
Ant Design has 3 types of Tabs for different situations. Card Tabs: for managing too many closeable views. Normal Tabs: for functional aspects...
Read more >
Ant Design Custom Tabs with react Router v6 - Stack Overflow
i used the custom Tab in different occasion and i want to route each one of them specifically, for exemple url/Notifications/tab1, url/ ...
Read more >
Tabs - Examples - Components - Atlassian Design System
Tabs are used to organize content by grouping similar information on the same page.
Read more >
CustomTab element in the manifest file - Office Add-ins
Use the <CustomTab> element to add a custom tab to the ribbon. On custom tabs, the add-in can have custom or built-in groups....
Read more >
CustomTab | Metadata API Developer Guide
Field Name Field Type Description description string The optional description text for the tab. fullName string hasSidebar boolean Indicates if the tab displays the sidebar panel....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found