Skip to content

Instantly share code, notes, and snippets.

@alexaivars
Created October 15, 2020 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexaivars/db849fed1510977b3dce54bb0fde2276 to your computer and use it in GitHub Desktop.
Save alexaivars/db849fed1510977b3dce54bb0fde2276 to your computer and use it in GitHub Desktop.
type ComponentProps = { text: string } & React.HTMLAttributes<HTMLDivElement>;
type ComponentRef = HTMLDivElement;
const Component:React.FunctionComponent<ComponentProps> = React.forwardRef<ComponentRef, ComponentProps>(
({ text = 'default', className }, ref) => (
<div className={className} ref={ref}>
{text}
</div>
),
);
type ComponentWithStyleProps = {
color: string;
ref: React.RefObject<HTMLDivElement> | null;
} & ComponentProps
type ComponentWithStyleType = StyledComponent<
React.FunctionComponent<ComponentProps>,
any,
ComponentWithStyleProps,
never
>;
export const ComponentWithStyle:ComponentWithStyleType = styled(Component)<ComponentWithStyleProps>`
border: 10px solid ${({ color }) => color};
`;
() => {
const ref = React.useRef<HTMLDivElement>(null)
return <ComponentWithStyle text='foo' color="red" ref={ref} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment