zustand-store-config.json file allows you to define default values for store creation. When you place this file in your project root, the CLI will automatically load and use these defaults during the interactive prompts.
File Location
The configuration file must be namedzustand-store-config.json and placed in your project’s root directory (the current working directory where you run the CLI).
Configuration Options
The configuration file supports the following properties:| Property | Type | Description | Default |
|---|---|---|---|
storeName | string | Default name for your store | "useStore" |
fileType | string | File type to generate (“JavaScript” or “TypeScript”) | "JavaScript" |
addPersist | boolean | Whether to add persistence middleware | false |
initialState | object or string | Default initial state for the store | {} |
actions | string | Comma-separated list of action names | "" |
packageManager | string | Package manager to use (“npm” or “yarn”) | "npm" |
storePath | string | Directory path where stores will be created | "store" |
Example Configuration
Here’s a complete example of azustand-store-config.json file:
Initial State Format
TheinitialState property accepts two formats:
Object Format (Recommended)
String Format
You can also provide initial state as a JSON string:Usage Workflow
- Create the config file: Add
zustand-store-config.jsonto your project root - Run the CLI: Execute the create-zustand-store command
- See defaults loaded: The CLI displays ”✔ Loaded default configuration” in green
- Override as needed: You can still modify values during the interactive prompts
Saving Configuration
You don’t have to manually create the configuration file. During the CLI prompts, you’ll be asked:zustand-store-config.json file with your current selections.
Error Handling
If the CLI encounters an error loading your configuration file (for example, invalid JSON), it will:- Display an error message: ”✘ Failed to load default configuration”
- Show the specific error details
- Continue with built-in defaults instead
Best Practices
- Commit to version control: Share consistent defaults across your team
- Use TypeScript by default: Set
"fileType": "TypeScript"for better type safety - Organize stores: Use a descriptive
storePathlike"src/stores"or"app/state" - Team conventions: Align package manager choice with your team’s standard