Skip to content

A collection of hooks I've created across various projects.

License

Notifications You must be signed in to change notification settings

emapco/react-util-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

react-util-hooks

A collection of hooks I've created across various projects.

useWindowSize usage

import { useMemo } from "react";
import { useScreenSize } from "path/to/hook/useScreenSize";


function App() {
  // object destruct the window size boolean states you are interested in
  const { isSmall, isLarge } = useWindowSize();

  // utilize the booleans as needed
  const iconSize = useMemo(() => {
    if (isLarge) return 30;
    if (isSmall) return 24;
    else return 22;
  }, [isSmall, isLarge]);
}

useAutoFocus usage

Useful when you want to auto focus an element when it enters the viewport. For example, to auto focus a search field when a dropdown is toggled open.

import { useMemo } from "react";
import { useAutoFocus } from "path/to/hook/useAutoFocus";


function App() {
  // object destruct the window size boolean states you are interested in
  const { ref, inViewport } = useAutoFocus();

  // pass ref to component/element that needs auto focus when visible
  return (<input ref={ref} />)
}

About

A collection of hooks I've created across various projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published