Could the custom Hook page https://reactjs.org/docs/hooks-custom.html
include one important rule:
#3557
Does any change of state in a custom Hook cause any component that uses it to re-render? Yes, when we use any Hook in our function, this function becomes a custom Hook, and when other components use it, any update of the state in this custom hook can cause the component to re-render. So we should not think of the custom Hook as a static function.
Or something along that line? Right now, it feels really magically that somehow, we define a function and it can magically cause another component to re-render itself.
A working example might even be added: https://codesandbox.io/s/suspicious-keller-blqey?file=/src/App.js
Could the custom Hook page https://reactjs.org/docs/hooks-custom.html
include one important rule:
#3557
Does any change of state in a custom Hook cause any component that uses it to re-render? Yes, when we use any Hook in our function, this function becomes a custom Hook, and when other components use it, any update of the state in this custom hook can cause the component to re-render. So we should not think of the custom Hook as a static function.
Or something along that line? Right now, it feels really magically that somehow, we define a function and it can magically cause another component to re-render itself.
A working example might even be added: https://codesandbox.io/s/suspicious-keller-blqey?file=/src/App.js