React Hooks

The React snippet collection contains function components and reusable hooks for React 16.

  • usePersistedState

    React, Hooks

    Returns a stateful value, persisted in localStorage, and a function to update it.

  • Wrapping your mind around React hooks and how they interact with setInterval() can be difficult. Here's a guide to get you started.

  • useKeyPress

    React, Hooks

    Listens for changes in the pressed state of a given key.

  • useSearchParam

    React, Hooks

    Tracks the browser's location search param.

  • useHash

    React, Hooks

    Tracks the browser's location hash value, and allows changing it.

  • useWindowSize

    React, Hooks

    Tracks the dimensions of the browser window.

  • useHover

    React, Hooks

    Handles the event of hovering over the wrapped component.

  • useScript

    React, Hooks

    Dynamically loads an external script.

  • useSSR

    React, Hooks

    Checks if the code is running on the browser or the server.

  • useGetSet

    React, Hooks

    Creates a stateful value, returning a getter and a setter function.

  • useAsync

    React, Hooks

    Handles asynchronous calls.

  • useBodyScrollLock

    React, Hooks

    Enables body scroll locking.

  • useNavigatorOnLine

    React, Hooks

    Checks if the client is online or offline.

  • useOnGlobalEvent

    React, Hooks

    Executes a callback whenever an event occurs on the global object.

  • useFetch

    React, Hooks

    Implements fetch in a declarative manner.