-
-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom function components and TypeScript #333
Comments
I made a codesandbox that "fixes" your issue: https://codesandbox.io/s/naughty-vaughan-iplny The differences are as follows: -import React, { FunctionComponent, ReactElement } from "react";
+import React, { FunctionComponent, ReactNode } from "react";
import { Tabs, TabList, TabPanel, Tab } from "react-tabs";
interface TabsProps {
panels: {
title: string;
- panelContent?: ReactElement;
+ panelContent?: ReactNode;
}[];
}
-const CustomTabPanel: FunctionComponent = ({ children }) => (
- <TabPanel>{children}</TabPanel>
+const CustomTabPanel: FunctionComponent = ({ children, ...otherProps }) => (
+ <TabPanel {...otherProps}>{children}</TabPanel>
);
+// @ts-ignore
+CustomTabPanel.tabsRole = "TabPanel";
const MyTabs: FunctionComponent<TabsProps> = (props: TabsProps) => {
const { panels } = props;
return (
<Tabs>
<TabList>
{panels.map(({ title }) => (
- <Tab title={title} key={title} />
+ <Tab key={title}>{title}</Tab>
))}
</TabList>
{panels.map(({ panelContent, title }) => (
<CustomTabPanel key={title}>{panelContent}</CustomTabPanel>
))}
</Tabs>
);
};
export default MyTabs; I put "fixes" between quotes because I didn't find a great way to add BTW the only reason I substituted |
Thanks for your answer! I will try it out in a bit. Really weird how we have to |
@anto66r have you found a better way to handle this problem? |
There is now a custom type for functional components, see the example in the Readme: https://github.com/reactjs/react-tabs#pass-through-properties |
🎉 This issue has been resolved in version 5.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi everyone, I'm having an issue using custom Functional components and TypeScript. The code below won't render the TabPanels, but the Tabs are shown.
I'm trying to apply this, but I'm not sure how that fits in with my code. Can somebody help?
The text was updated successfully, but these errors were encountered: