Grokking TypeScript
0% completed
Typing useRef, useContext, and useReducer
Three more hooks continue the user profile page from the previous lesson. The question also stays the same: when does inference give the right answer, and when must you supply the type yourself? Here the answer differs for each hook. useRef needs a type parameter when it points to a DOM element, useContext takes its type from the place where the context is created, and useReducer infers everything from the reducer function.
Typing useRef
A ref is an object that keeps a value between renders, in its current property, and changing it does not cause a new render
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%