Next.js
Install and configure reactuse for Next.js.
bash
npx create-next-app@latestEdit tsconfig.json file
Make sure your tsconfig.json includes the following paths configuration:
json
{
"compilerOptions": {
//...
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
}
//...
}
}Run the CLI
Run the useverse init command to setup your project:
bash
npx useverse@latest initThis will create a configuration file reactuse.json in your project.
Add hooks
You can now start adding hooks to your project:
bash
npx useverse@latest add useBooleanThe command above will add the useBoolean hook to your project. You can then import it like this:
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;