1.1.4 • Published 8 months ago

redux-cli-setup v1.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Redux Setup CLI šŸš€

A powerful CLI tool to instantly scaffold a production-ready Redux setup with Redux Toolkit, React-Redux, and Redux Persist integration.

Features ✨

  • šŸ› ļø Complete Redux folder structure generation
  • šŸ” Built-in authentication slice and API setup
  • šŸ“¦ Redux Persist integration
  • šŸŽÆ TypeScript support
  • šŸ”„ RTK Query setup with base API configuration
  • šŸŽØ Organized feature-based architecture

Prerequisites šŸ“‹

  • @reduxjs/toolkit
  • react-redux
  • redux-persist

Installation šŸ“„

npm install -g redux-cli-setup

Or use directly with npx:

npx redux-cli-setup

These must be installed in your project after running the CLI. If not, use:

npm install @reduxjs/toolkit react-redux redux-persist

Generated Structure šŸ“

src/
└── redux/
    ā”œā”€ā”€ base/
    │   ā”œā”€ā”€ baseApi.ts
    │   └── baseReducer.ts
    ā”œā”€ā”€ features/
    │   └── auth/
    │       ā”œā”€ā”€ authSlice.ts
    │       └── authApi.ts
    ā”œā”€ā”€ lib/
    │   └── ReduxProvider.tsx
    ā”œā”€ā”€ store.ts
    └── hooks.ts

File Breakdown šŸ“

1. Base Configuration

baseApi.ts

  • Centralized API configuration
  • Token refresh mechanism
  • Authentication header setup
  • Base URL configuration

baseReducer.ts

  • Combines reducers
  • Configures Redux Persist
  • Handles authentication state persistence

2. Authentication Feature

authSlice.ts

  • Manages authentication state
  • Provides setUser and logout actions
  • Defines user type with role-based access

authApi.ts

  • Authentication-related RTK Query endpoints
  • Supports:
    • User login
    • Email verification
    • Password management
    • Token handling

3. Store Configuration

store.ts

  • Configures Redux store
  • Sets up middleware
  • Integrates Redux Persist
  • Defines TypeScript types for store

hooks.ts

  • Provides typed Redux hooks
  • useAppDispatch and useAppSelector

4. Redux Provider

ReduxProvider.tsx

  • Wraps application with Redux Provider
  • Implements Redux Persist Gate

Usage Example šŸ’»

  1. Generate Redux structure:
npx redux-cli-setup
  1. Wrap your app with ReduxProvider:
import ReduxProvider from "@/redux/lib/ReduxProvider";

function App() {
  return (
    <ReduxProvider>
      <YourApp />
    </ReduxProvider>
  );
}
  1. Use in components:
import { useAppDispatch, useAppSelector } from "@/redux/hooks";
import { useLoginUserMutation } from "@/redux/features/auth/authApi";

function LoginComponent() {
  const dispatch = useAppDispatch();
  const [loginUser] = useLoginUserMutation();
  // Authentication logic
}

Authentication Endpoints šŸ”

  • loginUser: User authentication
  • verifyEmail: Email verification
  • forgetPassword: Initiate password recovery
  • resetPassword: Complete password reset
  • changePassword: Update password

Best Practices 🌟

  1. State Management

    • Use RTK Query for API calls
    • Implement comprehensive error handling
    • Leverage TypeScript for type safety
  2. Authentication

    • Secure token storage
    • Implement clean logout
    • Handle token expiration gracefully
  3. Performance Optimization

    • Minimize state updates
    • Implement efficient caching
    • Optimize component re-renders

Contributing šŸ¤

  1. Fork the repository
  2. Create feature branch
  3. Commit changes
  4. Push to branch
  5. Create Pull Request

License šŸ“„

MIT Ā© Apu Sutra Dhar

Support šŸ’¬


Made with ā¤ļø by Apu Sutra Dhar

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago