Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save wilmoore/4b60df8f67eb78a40044246ca52b6c56 to your computer and use it in GitHub Desktop.
Personal Brand :: Social Media :: LinkedIn :: Post :: React Custom Hooks Overview

Personal Brand :: Social Media :: LinkedIn :: Post :: React Custom Hooks Overview

⪼ Made with 💜 by Polyglot.

reference
research

» React Custom Hooks Overview «

The React Custom Hooks repository offers a collection of utility hooks designed to handle state management, asynchronous operations, media queries, dark mode toggling, geolocation, and more, simplifying common challenges in React development. Each hook provides a specialized function to streamline code for a variety of features, from clipboard copying to detecting user online status.

Explore these hooks further on GitHub for code snippets and detailed usage examples ↳ https://github.com/sergeyleschev/react-custom-hooks

Here’s a practical overview of the hooks with example code to get you started:

» 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://lnkd.in/gK5JynZv");

» 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://lnkd.in/gixiK6mt");

Țechśavvy CEO

image

💡 Have you already integrated some of these into your codebase? Let me know which ones you’d try first or share your favorite hook in the comments! 👇🏾

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