🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@m4rw3r/react-pause-champ

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@m4rw3r/react-pause-champ

Isomorphic React hook providing async-aware stateful variables to components, with Suspense and Server-Side-Rendering support

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

React Pause Champ

Isomorphic React hook providing async-aware stateful variables to components, with Suspense and Server-Side-Rendering support.

Features

Installation

npm install @m4rw3r/react-pause-champ

Dependencies

  • React 18

Recommended to use createRoot/hydrateRoot on the client to use batching. On the server renderToPipeableStream/renderToReadableStream is required for asynchronous initializations and Suspense support.

Examples

import { useChamp } from "@m4rw3r/react-pause-champ";

/**
 * Plain useState replacement with SSR-support.
 */
function Counter(): JSX.Element {
  const [data, update] = useChamp("my-counter", 0);

  return (
    <div>
      <p>{counter}</p>
      <button onClick={() => update((i) => i + 1)}>Increment</button>
    </div>
  );
}

/**
 * Isomorphic asynchronous fetch with SSR- and Suspense-support.
 */
function Page({ pageId }: { pageId: string }): JSX.Element {
  const [{ title, data }] = useChamp(`page.${pageId}`, async () => {
    const { title, data } = await fetchPageData();

    return { title: title.toUpperCase(), data };
  });

  return (
    <div>
      <h2>{title}</h2>
      <p>{data}</p>
    </div>
  );
}

/**
 * Asynchronous updates.
 */
function ServerCounter(): JSX.Element {
  const [value, update] = useChamp(
    "my-async-counter",
    async () => (await fetchCounter()).value
  );

  return (
    <div>
      <p>{value}</p>
      <button
        onClick={() =>
          update(
            async (old) =>
              (await fetchCounterUpdate({ newValue: old + 1 })).value
          )
        }
      >
        Increment
      </button>
    </div>
  );
}

Frequently Asked Questions

  • Uncaught Error: State '*' is already mounted in another component. when using Hot-Module-Reloading.

    This is caused by reordering components in JSX without using key. When key is skipped components will use the hooks from the previous component mounted in that "slot" instead, which will cause issues with use of useState/useRef/useEffect and so on. Pause Champ uses useRef to track component instances which can and will trigger exceptions if those values are not what it expects.

Keywords

async

FAQs

Package last updated on 19 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts