react-polymorphic-types
react-polymorphic-types copied to clipboard
How to use with styled components
Not strictly an issue of this library but a question about integrating with styled-components.
I have the following piece of code and styled-components is unable to deduce h1 attributes of StyledHeading. With only as={} suggested when creating a StyledHeading tag and any other attributes being any. Upon checking the typing from my IDE, I see that StyledHeading has type StyledComponent<PolymorphicForwardRefExoticComponent<P, any>, ...>.
import styled from 'styled-components'
export const Heading: PolymorphicForwardRefExoticComponent<
HeadingOwnProps,
typeof HeadingDefaultElement
>(...) => {...}
const StyledHeading = styled(Heading).attrs({
forwardedAs: 'h1' // or as: 'h1'
})``