Hooks 11 exercises
Problem

Basic useRef Typing

Here we have a Component that uses useRef.

Inside the component is a mutable ref object called id, along with a useEffect that assigns a random value to id.current:


export const Component = () => {
const id = useRef();
useEffect(() => {
// error under id.current

Loading exercise

Transcript

0:00 Let's take a look at useRef here. We have a component that inside it has an ID. In a useEffect, we're assigning that ID to a random value. The way that this works is we have id, which is a MutableRefObject, and id.current is basically the API, so id.current, current is the only property on this id-ref.

0:23 We're having an error here, which is id.current is not assignable to type undefined. Your job is to figure out how we can fix it without actually changing any of the runtime code. Good luck.