-> Custom Hook is a js function where you can create yourself a own reuse stateful logic or other react hook logic can write in the component that returns the value
-> Js function starts with "use"
-> It returns the value or function to the other components can use.
syntax:
function useHookName(){
//hooks and logic
return value;
}
eg:
function UseCounter(){
const [count, setCount] = useState(0);
return count;
}
function App(){
const count = UseCounter();
return (
Setcount( count +1)> +
}
}
-> here the useCounter has created and provide a stateful logic code, also it returns the value/functions to the component using it.
-> that useCounter custom hook call in other components it executes the logic in that function.
Top comments (0)