import { useState, useEffect } from 'react';

const useHash = () => {
  const [state, setState] = useState(() => {
    return window.location.hash;
  });

  useEffect(() => {
    const handler = () => {
      setState(window.location.hash);
    };
    window.addEventListener('hashchange', handler);
    return () => window.removeEventListener('hashchange', handler);
  }, []);

  return state;
};

export default useHash;
