So, I'm trying to implement the react forwardref example for my component, as I want to control a scrollbar inside.
Here's what I have:
const MessagesFC = React.forwardRef((props, ref) => {
return <Flex
className={"Messages"}
direction={"Column"}
ref={ref}>
{messages}
</Flex>
});
const scrollDivRef = React.createRef<any>();
React.useEffect(() => {
scrollDivRef.current?.scrollIntoView({ behavior: "smooth"})
}, [ scrollDivRef, chatRoom.messages ])
Inside my return(), the component is added like this:
<MessagesFC
ref={scrollDivRef}/>
Seems to be setup just like in the example.
However, when executing this code, the scrollDivRef.current is always undefined.
So, where did I go wrong?
Screenshot of my code: