Facebook Pixel

What are examples of custom hooks in React?

useFetch for fetching data with loading and error, useForm for managing form state with validation, and useLocalStorage for syncing state to localStorage. These use state or effects, so they are hooks.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Custom Hooks vs Utility Functions: How to Choose in React

If the logic uses state or effects, use a custom hook. If it is pure, taking inputs and returning outputs with no hooks, use a utility function. The presence of hooks is the deciding factor.

A utility function is a plain function with no state or side effects, usable anywhere. A custom hook starts with 'use', uses React hooks internally, and can only be called from components or other hooks.

Because it adds the rules of hooks for no benefit. Pure logic as a utility function is simpler, can be used outside React, and is easier to test. Wrapping it in a hook creates unnecessary constraints.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0