TanStack Router
Install and configure reactuse for TanStack Router.
Create project
Start by creating a new TanStack Router project:
bash
npx create-tsrouter-app@latest my-app --template file-router --tailwindEdit tsconfig.json file
Ensure your tsconfig.json includes path aliases:
json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}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
import { createFileRoute } from '@tanstack/react-router';
import { useBoolean } from '@/shared/hooks';
export const Route = createFileRoute('/')({
component: Home
});
const Home = () => {
const [on, toggle] = useBoolean();
return (
<div>
<button type='button' onClick={() => toggle()}>
Click me
</button>
<p>{on.toString()}</p>
</div>
);
};