I'm implementing a link in React and TypesSript that, after clicking, scrolls to the right component, I'm using useRef Hook.
But when I do that, the error occurs:
Type '{ ref: MutableRefObject<HTMLDivElement | null>; }' is not assignable to type 'IntrinsicAttributes'.
Property 'ref' does not exist on type 'IntrinsicAttributes'.
Below is the code, what am I doing wrong? I've tried several ways.
import NewComponent from '../NewComponent';
const titleRef = useRef<null | HTMLDivElement>(null);
const handleBackClick = (): any => {
titleRef!.current!.scrollIntoView({ behavior: 'smooth' });
};
return (
<Container>
<Link onClick={handleBackClick}>
Button Text
</Link>
...
...
...
<SomeComponents />
...
...
...
...
<NewComponent ref={titleRef} />
</Container>
)
The NewComponent is a simple component, like:
const NewComponent = () => {
return (
<Container>
// Its a simple component
</Container>
);
};
export default NewComponent;
Thanks to anyone who can help me with this!