DEV Community

Mukesh
Mukesh

Posted on

Custom hooks in react

Custom hooks are js function that allows us to reuse the stateful logic between multiple component.

ex:

If you want to write a same logic in multiple components, here comes custom hooks you write those logic into a single component and export it , its acts as a hook you just import into another component .

syntax:
function usemyhook{

return{}
}
export default usemyhook

The component name must start with use.

A custom hook must return anything what you specified in the return statement.Everything else remains local to that custom hook.

Top comments (0)