Overview
Thecreate-zustand-store command is the main CLI tool for generating Zustand stores. When you run the command, it launches an interactive prompt that guides you through configuring your store.
Usage
Interactive Prompts
When you run the command, you’ll be prompted to configure your store with the following options:- Store name - The name of your store (default:
useStore) - File type - Choose between JavaScript or TypeScript
- Persistence - Whether to add persistence to your store
- Initial state - Define your initial state properties as JSON
- Actions - Define store actions (comma-separated)
- Package manager - Choose between npm or yarn
- Store path - Custom directory path for the store
- Save configuration - Save your settings as defaults for future use
What It Does
The command will:- Create a new Zustand store file in your specified directory
- Generate the store with your initial state and actions
- Automatically install Zustand if it’s not already installed
- Optionally save your configuration for future store creation
Configuration File
If you choose to save your configuration, the CLI creates azustand-store-config.json file in your project root. This file stores your default preferences and is automatically loaded when you run the command again.
Example Workflow
Next Steps
After creating your store:- Import and use the store in your React components
- Customize the generated actions to implement your business logic
- Add additional state properties and actions as needed