- useState: allows you to add state to functional components
- useEffect: allows you to add side effects (e.g., data fetching, event listeners) to your components
- useContext: allows you to access a context object created by a ContextProvider component
- useRef: allows you to create a mutable reference that persists across renders
- useReducer: an alternative to useState that allows you to manage more complex state in a functional way .
To use a hook in a functional component, you simply call it at the top level of your component, and then use the values it returns in your JSX. For example:
In the example above, we're using the useState hook to add state to our Counter component. The hook returns an array with two values: the current state value (count) and a function to update the state (setCount). We then use these values to display the current count and update it when the button is clicked.
No comments:
Post a Comment