Skip to content

Custom function components and TypeScript #333

Closed
@anto66r

Description

@anto66r

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.

import React, { FunctionComponent, ReactElement } from 'react';
import {
  Tabs, TabList, TabPanel, Tab,
} from 'react-tabs';

interface TabsProps {
  panels: {
    title: string;
    panelContent?: ReactElement;
  }[];
}

const CustomTabPanel: FunctionComponent = ({ children }) => (
  <TabPanel>
    {children}
  </TabPanel>
);

const MyTabs: FunctionComponent<TabsProps> = (props: TabsProps) => {
  const {
    panels,
  } = props;

  return (
    <Tabs>
      <TabList>
        {panels.map(({ title }) => <Tab title={title} key={title} />)}
      </TabList>
      {
        panels.map(({ panelContent, title }) => <CustomTabPanel key={title}>{panelContent}</CustomTabPanel>)
      }
    </Tabs>
  );
};

export default MyTabs;

I'm trying to apply this, but I'm not sure how that fits in with my code. Can somebody help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions