What is the custom hook in react? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the custom hook in react?

28th Jul 2020, 3:24 AM
Sepideh
Sepideh - avatar
2 Answers
28th Jul 2020, 3:36 AM
Kevin ★
+ 3
Custom hook is quite similar to functional component, the difference are 1. custom hook name the function with use*, eg. useCustomDialog 2. custom hook function can carry input parameters eg. input text for the state/component 3. The function instead of return jsx code like functional component does, custom hooks returns object of state, private function or component. So the main task of custom hook is to allow react code to build state, and component beforehand for its react components. Sepideh Masoomi Study the below example, you would understand how custom hook works and helps build a cleaner react code. https://code.sololearn.com/W2ZCTp4VKSaQ/?ref=app
11th Sep 2021, 1:08 AM
Calviղ
Calviղ - avatar