What are custom hooks in React?

Custom hooks are reusable functions that encapsulate logic using hooks, allowing for modular and cleaner code.

function useFetch(url) {
  const [data, setData] = useState(null);
  useEffect(() => {
    fetch(url)
      .then(response => response.json())
      .then(setData);
  }, [url]);
  return data;
}