Custom Hooks and Utility Functions

Creating Reusable Custom Hooks

Custom hooks can be created for reusable logic, like fetching data. Example:

import { useState, useEffect } from "react";

function useFetch(url) {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetch(url)
      .then((response) => response.json())
      .then((data) => setData(data));
  }, [url]);

  return data;
}

Organizing Utility Functions

Place utility functions in a utils folder for easy access across components.