React Hooks

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

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

  • usePersistedState

    React, Hooks

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

  • useSSR

    React, Hooks

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

  • useAsync

    React, Hooks

    Handles asynchronous calls.

  • useNavigatorOnLine

    React, Hooks

    Checks if the client is online or offline.

  • useFetch

    React, Hooks

    Implements fetch in a declarative manner.

  • useUnload

    React, Hooks

    Handles the beforeunload window event.

  • useDebounce

    React, Hooks

    Debounces the given value.

  • useClickInside

    React, Hooks

    Handles the event of clicking inside the wrapped component.

  • useClickOutside

    React, Hooks

    Handles the event of clicking outside of the wrapped component.

  • useMediaQuery

    React, Hooks

    Checks if the current environment matches a given media query and returns the appropriate value.

  • useCopyToClipboard

    React, Hooks

    Copies the given text to the clipboard.

  • useTimeout

    React, Hooks

    Implements setTimeout in a declarative manner.

  • Executes a callback immediately after a component is mounted.

  • Executes a callback immediately before a component is unmounted and destroyed.