Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active October 28, 2024 19:31
Show Gist options
  • Select an option

  • Save wilmoore/d793e6c3d291855bcc4dd8a280b50ba6 to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/d793e6c3d291855bcc4dd8a280b50ba6 to your computer and use it in GitHub Desktop.
Software Engineering :: Programming :: Languages :: JavaScript :: Library :: react-custom-hooks

Software Engineering :: Programming :: Languages :: JavaScript :: Library :: react-custom-hooks

⪼ Made with 💜 by Polyglot.

content
research

React Custom Hooks is a repository providing utility hooks that simplify React development, from handling state and async operations to media queries, geolocation, and more. Each hook streamlines specific functionality, making your code cleaner and more efficient. See the full list and details here: React Custom Hooks.

API

useArray
const { value, push, remove } = useArray([1, 2, 3]);
push(4); // Adds 4 to the array
useAsync
const { data, error, loading } = useAsync(fetchData);
useClickOutside
const ref = useClickOutside(() => console.log('Clicked outside!'));
useCookie
const [cookie, setCookie] = useCookie("userToken", "");
useCopyToClipboard
const [copy] = useCopyToClipboard();
copy("Text to copy!");
useDarkMode
const [isDarkMode, toggleDarkMode] = useDarkMode();
useDebounce
const debouncedValue = useDebounce(value, 500);
useDebugInformation
const debugInfo = useDebugInformation("ComponentName", props);
useDeepCompareEffect
useDeepCompareEffect(() => { /* effect */ }, [complexDependency]);
useEffectOnce
useEffectOnce(() => { console.log("Runs only once"); });
useEventListener
useEventListener("scroll", handleScroll);
useFetch
const { data, error } = useFetch("https://api.example.com/data");
useGeolocation
const { coords, error } = useGeolocation();
useHover
const [hoverRef, isHovered] = useHover();
useLongPress
const longPress = useLongPress(() => console.log("Long pressed!"));
useMediaQuery
const isLargeScreen = useMediaQuery("(min-width: 1024px)");
useOnlineStatus
const isOnline = useOnlineStatus();
useOnScreen
const [ref, isOnScreen] = useOnScreen();
usePrevious
const prevValue = usePrevious(value);
useRenderCount
const renderCount = useRenderCount();
useScript
const status = useScript("https://example.com/script.js");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment