Adjusting the Custom Hook Logic

Adjusting the Custom Hook Logic

·

1 min read

When the states are set the component where we use the custom hook will be re-rendered because when you use a custom hook, which uses state and you use that hook in that component that component will implicitly use that state set up in the custom hook.

So the state configured in the custom hook is attached to the component where you use the custom hook. So if we call set is loading and set error here in the send request function in the custom hook this will trigger the app component to be re-evaluated because I'm using that custom hook here in that component.

So, when we use a custom hook :

App.js

const { isLoading, error, sendRequest: fetchTasks } = useHttp();

inside a component App.js , this component will re-rendered and re-evaluted such as usehttp.js