By default, the useRef initial value is recreated on every render even though it's ignored after the first render.
If the useRef initial value is an object that we create, we might want to avoid recreating it unnecessarily.
In this video, I'll show how we can implement lazy initialization with useRef to avoid recreating the initial value.
I will also show how to properly clean up the ref value when the component unmounts.
00:00 Initial value is recreated
00:21 Lazy initialization
00:46 Cleaning up the ref value
Тэги:
#useRef_lazy_initialization #useRef_initial_value #useRef_hook #ref_hook #react_hooks #react #reactjs