1
0

useHovering.ts 461 B

1234567891011121314151617
  1. import { useCallback, useState } from 'react';
  2. export const useHovering = (animate?: boolean) => {
  3. const [hovering, setHovering] = useState<boolean>(animate ?? false);
  4. const handleMouseEnter = useCallback(() => {
  5. if (animate) return;
  6. setHovering(true);
  7. }, [animate]);
  8. const handleMouseLeave = useCallback(() => {
  9. if (animate) return;
  10. setHovering(false);
  11. }, [animate]);
  12. return { hovering, handleMouseEnter, handleMouseLeave };
  13. };