Search code examples
reactjsreact-hooksuse-statereact-custom-hooks

Would a component re-render if state inside of custom hook changes?


In my React app, I have a custom defined hook that holds a useState value internally, but the custom hook itself does not return any values.

If the value of its internal useState changes would this cause the component that calls this custom hook to re-render?


Solution

  • Yes it re-renders the component. The custom hooks helps to reuse stateful logic in different components, but in the end, when you use a custom hooks all states and effects inside of it are part of the component where you called the custom hook. So yes, the change of state inside the custom hooks re-renders the component where you used your custom hook, even when this does not return anything.