Skip to content

Next.js

Install and configure reactuse for Next.js.

Create project

Create a new Next.js app or use an existing one:

bash
npm create next-app@latest
bash
yarn create next-app
bash
pnpm create next-app
bash
bun create next-app

Edit tsconfig.json file

Add baseUrl and paths so the CLI and imports resolve correctly. Use "./*" if the app lives in the project root, or "./src/*" if you use a src directory:

json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    }
  }
}

Run the CLI

Run the useverse init command to set up your project:

bash
npx useverse@latest init

This creates a reactuse.json config file in your project.

Add hooks

Add hooks with the CLI:

bash
npx useverse@latest add useBoolean

Then import and use the hook (e.g. in app/page.tsx). Use 'use client' when the component uses hooks:

tsx
'use client';

import { useBoolean } from '@/shared/hooks';

const Home = () => {
  const [on, toggle] = useBoolean();

  return (
    <div>
      <button onClick={() => toggle()}>Click me</button>
      <p>{on.toString()}</p>
    </div>
  );
};

export default Home;

Released under the MIT License.