Recently I came across some weird usage of useMemo hook:
const memo = useMemo(callback, false);
As a second argument, instead of dependency is passed false.
Is this a valid code? React documentation states that dependency should be an array. What is the purpose of using false?
Is this a valid code?
It depends on what you mean by valid
.
Is it a valid call to React API? no.
While this code works today, passing false
as dependency list is not mentioned in the documentation and the behaviour can change in any future react release.
In summary: update your code to useMemo(callback, [])
.
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