npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

react-state-cli

v1.1.0

Published

🧠 Effortless Redux boilerplate generation from initial state files - Generate Redux Toolkit slices, reducers, and TypeScript interfaces automatically

Readme

React State CLI

🧠 Effortless Redux boilerplate generation from initial state files

npm version License: MIT CI Release CodeQL

A powerful CLI tool that automatically generates Redux Toolkit slices, reducers, TypeScript interfaces, and state management boilerplate from your initial state definitions. Say goodbye to repetitive Redux setup!

✨ Features

  • πŸš€ Zero Configuration - Works out of the box with sensible defaults
  • πŸ“ TypeScript First - Generates fully typed Redux code
  • πŸ”§ Redux Toolkit - Uses modern Redux patterns with RTK
  • ⚑ Lightning Fast - Instant boilerplate generation
  • 🎯 Smart Type Inference - Automatically infers types from your initial state
  • πŸ“ Organized Structure - Generates clean, maintainable file organization
  • πŸ”„ Action Creators - Auto-generates setter actions for each state property

πŸ“¦ Installation

Global Installation (Recommended)

npm install -g react-state-cli

Local Installation

npm install --save-dev react-state-cli

Using npx (No Installation Required)

npx react-state-cli generate ./src/redux/product/initState.ts

πŸš€ Quick Start

1. Create your initial state file

Create an initState.ts file that exports a default object:

// src/redux/product/initState.ts
export default {
  items: [],
  loading: false,
  error: null,
  selectedId: 0,
  filters: {
    category: '',
    priceRange: [0, 1000]
  }
}

2. Generate Redux boilerplate

react-state-cli generate ./src/redux/product/initState.ts

3. ✨ Magic happens!

The CLI will generate:

src/redux/product/
β”œβ”€β”€ initState.ts          # Your original file
β”œβ”€β”€ slice.ts              # Redux Toolkit slice
β”œβ”€β”€ reducers.ts           # Exported reducer
β”œβ”€β”€ types.ts              # TypeScript interfaces
└── ...

src/redux/
└── state.ts              # Root state interface (if new)

πŸ“š Generated Code Examples

Generated Slice (slice.ts)

import { createSlice } from '@reduxjs/toolkit'
import { ProductState } from './types'

const initialState: ProductState = {
  items: [],
  loading: false,
  error: null,
  selectedId: 0,
  filters: {
    category: '',
    priceRange: [0, 1000]
  }
}

const productSlice = createSlice({
  name: 'product',
  initialState,
  reducers: {
    setItems: (state, action) => { state.items = action.payload },
    setLoading: (state, action) => { state.loading = action.payload },
    setError: (state, action) => { state.error = action.payload },
    setSelectedId: (state, action) => { state.selectedId = action.payload },
    setFilters: (state, action) => { state.filters = action.payload },
  }
})

export const { setItems, setLoading, setError, setSelectedId, setFilters } = productSlice.actions
export default productSlice.reducer

Generated Types (types.ts)

export interface ProductState {
  items: any[]
  loading: boolean
  error: any
  selectedId: number
  filters: object
}

Generated Root State (state.ts)

import { ProductState } from './product/types'

export interface RootState {
  product: ProductState
}

πŸ› οΈ CLI Commands

generate

Generates Redux boilerplate from an initial state file.

react-state-cli generate <initStatePath>

Arguments:

  • <initStatePath> - Path to your initState.ts file (relative or absolute)

Examples:

# Relative path
react-state-cli generate ./src/redux/user/initState.ts

# Absolute path
react-state-cli generate /Users/dev/project/src/redux/auth/initState.ts

# Using npx
npx react-state-cli generate ./src/store/products/initState.ts

πŸ“‹ Requirements

  • Node.js >= 14.0.0
  • TypeScript project setup
  • Redux Toolkit in your dependencies

🎯 Use Cases

Perfect for:

  • πŸ—οΈ New Redux slices - Quickly scaffold new state management
  • πŸ”„ Rapid prototyping - Generate boilerplate for quick testing
  • πŸ“š Learning Redux - See best practices in generated code
  • 🏒 Team consistency - Ensure uniform Redux patterns across teams
  • ⚑ Time-saving - Eliminate repetitive boilerplate writing

Example Project Structure

src/
β”œβ”€β”€ redux/
β”‚   β”œβ”€β”€ user/
β”‚   β”‚   β”œβ”€β”€ initState.ts
β”‚   β”‚   β”œβ”€β”€ slice.ts          # Generated
β”‚   β”‚   β”œβ”€β”€ reducers.ts       # Generated
β”‚   β”‚   └── types.ts          # Generated
β”‚   β”œβ”€β”€ products/
β”‚   β”‚   β”œβ”€β”€ initState.ts
β”‚   β”‚   β”œβ”€β”€ slice.ts          # Generated
β”‚   β”‚   β”œβ”€β”€ reducers.ts       # Generated
β”‚   β”‚   └── types.ts          # Generated
β”‚   └── state.ts              # Generated root state
β”œβ”€β”€ components/
└── pages/

βš™οΈ Configuration

Currently, the CLI uses sensible defaults and doesn't require configuration. Future versions may include:

  • Custom template support
  • Configurable naming conventions
  • Output directory customization
  • Advanced type inference options

🀝 Contributing

We welcome contributions! Here's how to get started:

Development Setup

# Clone the repository
git clone https://github.com/Utsav-Virani/react-state-cli.git
cd react-state-cli

# Install dependencies
npm install

# Build the project
npm run build

# Link for local development
npm link

# Test your changes
react-state-cli generate ./examples/initState.ts

Project Structure

react-state-cli/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts          # CLI entry point
β”‚   β”œβ”€β”€ generate.ts       # Core generation logic
β”‚   └── utils.ts          # Utility functions
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ slice.ts.tpl      # Redux slice template
β”‚   β”œβ”€β”€ reducers.ts.tpl   # Reducer export template
β”‚   └── state.ts.tpl      # Root state template
β”œβ”€β”€ dist/                 # Compiled output
└── package.json

Contributing Guidelines

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

MIT License - see the LICENSE file for details.

πŸ› Issues & Support

πŸ—ΊοΈ Roadmap

  • [ ] Custom templates - Support for user-defined templates
  • [ ] Advanced type inference - Better handling of complex nested objects
  • [ ] Multiple slice generation - Batch processing of multiple state files
  • [ ] Integration plugins - VS Code extension, IDE plugins
  • [ ] Configuration file - .react-state-cli.json for project settings
  • [ ] Testing utilities - Generate test files alongside Redux code

πŸ™‹ FAQ

Q: Can I use this with existing Redux setups? A: Yes! The CLI generates standard Redux Toolkit code that integrates seamlessly with existing Redux stores.

Q: Does it work with JavaScript projects? A: Currently, the CLI is designed for TypeScript projects. JavaScript support is planned for future releases.

Q: Can I customize the generated code? A: The CLI uses EJS templates that can be modified. Future versions will support custom templates.

Q: What if my initial state has complex nested objects? A: The CLI handles nested objects but may infer them as object type. You can manually refine the generated types.


Made with ❀️ by Utsav Virani

Star ⭐ this repo if you find it useful!