marty-wang/stylist-react

Style components don't forward refs to the underlying components

Closed this issue · 2 comments

const TitleLabel = styleSpan('TitleLabel', theme => ({
    fontWeight: theme.titleLabelFontWeight as FontWeightProperty
}));


const MyComp = () => {
    const ref = React.useRef();

    React.useEffect(() => {
        console.log(ref); // this will log the component instance not the underlying DOM node and AFAIK there isn't a way to access the DOM node, there are originalRef and itemRef but both yield `undefined` 
    })

    return <TitleLabel ref={ref}></TitleLabel>
}

You can refer to this: https://reactjs.org/docs/forwarding-refs.html

try originalRef property

originalRef works