Skip to content

Instantly share code, notes, and snippets.

@Sensiblemnd
Last active January 29, 2020 02:35
Show Gist options
  • Save Sensiblemnd/ba70e27d6ea3f1c5273a42c37d1b35b2 to your computer and use it in GitHub Desktop.
Save Sensiblemnd/ba70e27d6ea3f1c5273a42c37d1b35b2 to your computer and use it in GitHub Desktop.
accordion.tsx
import React from "react";
type AccordionType = {
children: React.ReactNode[] | React.ReactNode;
};
const Accordion = (props: AccordionType) => {
return <div className="accordion">{props.children}</div>;
};
//Yay, namespacing!
Accordion.Button = (props: AccordionType) => {
return <h3 className="accordion__title">{props.children}</h3>;
};
Accordion.Panel = (props: AccordionType) => {
return <div>{props.children}</div>;
};
Accordion.Trigger = (props: AccordionType) => {
return <div>{props.children}</div>;
};
//You can give your subcomponents any name that you want, and it is what shows up in the dev tools.
// @ts-ignore
Accordion.Button.displayName = "Accordion.Trigger";
// @ts-ignore
Accordion.Panel.displayName = "Accordion.Panel";
export default Accordion;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment