Created
October 15, 2020 12:56
-
-
Save alexaivars/db849fed1510977b3dce54bb0fde2276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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