React · Middle · Question 73 of 75
Why shouldn't you read or write ref.current during render?
- ✓Correct answer: It makes rendering impure and unpredictable; refs are meant for event handlers and effects
- 2It throws an error in production
- 3Refs are
nulluntil the app is unmounted
Explanation
The exception is lazy initialization: if (ref.current === null) ref.current = new Thing(). Otherwise React can't know about the change.