React Refs with TypeScript: Cannot read property 'current' of undefined
问题 I'm building a React application using TypeScript. I want to create button, that scrolls to a header of a child component on my main page. I've created a ref in the child component, following this stack overflow answer and (tried to) use forward refs to access it on my parent component. export class Parent extends Component { private testTitleRef!: RefObject<HTMLHeadingElement>; scrollToTestTitleRef = () => { if (this.testTitleRef.current !== null) { window.scrollTo({ behavior: "smooth", top: