Skip to content

thepuskar/react-rsc-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

165 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

react-rsc-kit

Typed React hooks and utility components with explicit RSC-safe and client entrypoints for Next.js App Router and other React 18+ apps.

npm version npm downloads Docs License: MIT

Links

Install

npm install react-rsc-kit

Usage

Component (server-safe)

import { Match, Show, Switch } from "react-rsc-kit";

export function Greeting({ user }: { user: { name: string } | null }) {
  return (
    <Show when={user} fallback={<p>Please sign in</p>}>
      {(u) => <p>Welcome, {u.name}</p>}
    </Show>
  );
}

export function Status({ user }: { user: { name: string } | null }) {
  return (
    <Switch fallback={<p>Please sign in</p>}>
      <Match when={user}>{(u) => <p>Welcome, {u.name}</p>}</Match>
    </Switch>
  );
}

Hook (client-only)

"use client";

import { useToggle } from "react-rsc-kit/client";

export function ToggleButton() {
  const [on, toggle] = useToggle(false);
  return <button onClick={() => toggle()}>{on ? "ON" : "OFF"}</button>;
}

RSC Guidance

  • react-rsc-kit and react-rsc-kit/server are server-safe entrypoints.
  • react-rsc-kit/client and react-rsc-kit/hooks are client entrypoints.
  • In Next.js App Router, import hooks/client-only APIs only from .../client (or .../hooks) inside files that have "use client".

Development

npm install
npm run build
npm run test
npm run lint
npm run format:check

Community

About

React hooks and utility components with RSC-safe server and client entrypoints.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages