I am little bit confuse about it! Is there any difference if we pass or don't pass null as an initial parameter in useRef? Like when we create state in functional component of React Js, we pass null as first value and then we update it! What if we also pass null in useRef like
const ref = useRef();
Or
const ref = useRef(null);
Both are correct?
Both are correct but have different meanings.
const ref = useRef();
is (since unpassed parameters are undefined) the same as
const ref = useRef(undefined);
so the initial value of the ref is undefined, while with
const ref = useRef(null);
the initial value is null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With