Advanced Hooks 8 exercises
Problem

Fixing Type Inference in a Custom React Hook

In this exercise, we have a custom React hook called useID.

This hook takes in a default ID, uses it in a useState, and then returns the result of the useState back from useID:


export const useID = (defaultID: string) => {
const [id, setID] = useState(defaultID);
return [i

Loading exercise

Transcript

00:00 In this exercise, we have a hook called useID. And what useID is doing is it takes in a default ID, sticks that in a useState, and then returns the results of the useState back from useID. This all seems fine, but when we actually go to useID, you can see that we don't have things like toUpperCase on it,

00:18 which is surprising because inside here, it's inferred as a string. Your job here is to try to figure out how you can change this function without changing the runtime behavior to actually return the right thing. And a couple of clues here might be gleaned from hovering over setID and hovering over ID to see what's happening.

00:38 So that's your job. Good luck.