1.1.4 ⢠Published 8 months ago
redux-cli-setup v1.1.4
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
andlogout
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
anduseAppSelector
4. Redux Provider
ReduxProvider.tsx
- Wraps application with Redux Provider
- Implements Redux Persist Gate
Usage Example š»
- Generate Redux structure:
npx redux-cli-setup
- Wrap your app with
ReduxProvider
:
import ReduxProvider from "@/redux/lib/ReduxProvider";
function App() {
return (
<ReduxProvider>
<YourApp />
</ReduxProvider>
);
}
- 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 authenticationverifyEmail
: Email verificationforgetPassword
: Initiate password recoveryresetPassword
: Complete password resetchangePassword
: Update password
Best Practices š
State Management
- Use RTK Query for API calls
- Implement comprehensive error handling
- Leverage TypeScript for type safety
Authentication
- Secure token storage
- Implement clean logout
- Handle token expiration gracefully
Performance Optimization
- Minimize state updates
- Implement efficient caching
- Optimize component re-renders
Contributing š¤
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
License š
MIT Ā© Apu Sutra Dhar
Support š¬
- Issues: GitHub Issues
- Docs: NPM Package
Made with ā¤ļø by Apu Sutra Dhar