A powerful and lightweight React hook library that simplifies Redux state management with a familiar useState-like API. Built on top of Redux Toolkit for optimal performance and developer experience
Documentation/demo | Npm Registry | GitHub Repo
- π― Simple API: Use redux State with a familiar
useState-like interface - π Dynamic State Creation: Automatically create and manage Redux slices on-demand
- π¨ TypeScript Support: Full TypeScript support with excellent type inference
- β‘ Performance Optimized: Built on Redux Toolkit for optimal performance
- π§ Flexible Selectors: Advanced state selection capabilities
- π Zero Configuration: Minimal setup required
- π¦ Lightweight: Small bundle size with no unnecessary dependencies
npm install redux-toolkit-stateor
yarn add redux-toolkit-stateimport { GlobalReduxProvider } from 'use-toolkit-state';
function App() {
return (
<GlobalReduxProvider>
<YourApp />
</GlobalReduxProvider>
);
}import { useReduxState } from 'use-toolkit-state';
function Counter() {
const [count, setCount] = useReduxState('counter', 0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}The main hook for managing redux State. Works just like useState but with global scope.
Parameters:
key(string): Unique identifier for the redux StateinitialValue(optional): Initial value for the state
Returns:
value: Current state valuesetValue: Function to update the entire stateupdate: Function to merge partial updatesreset: Function to reset state to initial value
const [value, setValue, { update, reset }] = useReduxState(key, initialValue);Get the entire value of a redux State without a selector.
const value = useReduxStateValue(key);Provide only Setter [setVal,update]
const [setValue, update] = useReduxStateSetValue(key);
// update (partially)
// setValue (setter)Provide Reset Handler to reset Particular slice to its initial state
const resetFnc = useReduxStateReset(key);
//call while need
resetFnc();Select specific parts of redux State with a selector function.
const selectedValue = useReduxStateSelector(key, (state) => state.someProperty);Select multiple redux States at once.
const states = useMultipleGlobalStates(['user', 'settings', 'theme']);import { useReduxState } from 'use-toolkit-state';
function UserProfile() {
const [user, setUser] = useReduxState('user', {
name: 'John Doe',
email: 'john@example.com',
age: 30,
});
const updateName = (newName: string) => {
setUser({ ...user, name: newName });
};
return (
<div>
<h2>{user.name}</h2>
<p>{user.email}</p>
<button onClick={() => updateName('Jane Doe')}>Update Name</button>
{/**`DATA` accessible to the child component **/}
<ChildComponent />
</div>
);
}
const ChildComponent = () => {
// getter variable with state
const [userState] = useReduxState('user');
// without state (value getter)
const user = useReduxStateValue('user');
return <div>{user.name}</div>;
};function Settings() {
const [settings, setSettings, { update }] = useReduxState('settings', {
theme: 'light',
language: 'en',
notifications: true,
});
const toggleTheme = () => {
update({ theme: settings.theme === 'light' ? 'dark' : 'light' });
};
return (
<div>
<p>Current theme: {settings.theme}</p>
<button onClick={toggleTheme}>Toggle Theme</button>
</div>
);
}function UserList() {
// Select only the users array from the State
const users = useReduxStateSelector('users', (state) => state.list);
// Select multiple states
const { user, settings } = useMultipleGlobalStates(['user', 'settings']);
return (
<div>
<h3>Welcome, {user.name}!</h3>
<p>Theme: {settings.theme}</p>
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
</div>
);
}function ShoppingCart() {
const [cart, setCart, { update, reset }] = useReduxState('cart', {
items: [],
total: 0,
});
const addItem = (item) => {
const newItems = [...cart.items, item];
const newTotal = newItems.reduce((sum, item) => sum + item.price, 0);
update({ items: newItems, total: newTotal });
};
const clearCart = () => {
reset(); // Reset to initial state
};
return (
<div>
<h3>Shopping Cart ({cart.items.length} items)</h3>
<p>Total: ${cart.total}</p>
<button onClick={clearCart}>Clear Cart</button>
</div>
);
}import { clearSlices, getRegisteredKeys, getStore } from 'use-toolkit-state';
// Get the store instance
const store = getStore();
// Get all registered state keys
const keys = getRegisteredKeys();
// Clear all slices (useful for testing)
clearSlices();interface User {
id: string;
name: string;
email: string;
}
interface AppState {
user: User;
settings: {
theme: 'light' | 'dark';
language: string;
};
}
function TypedComponent() {
const [user, setUser] = useReduxState<User>('user', {
id: '1',
name: 'John Doe',
email: 'john@example.com',
});
const settings = useReduxStateValue<AppState['settings']>('settings');
}We welcome contributions from the community! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following our coding standards
- Add tests for new functionality
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Fork and clone the repository
git clone https://github.com/rajkumar4041/use-redux-state.git
cd use-redux-state
# Install dependencies
npm install
# Start development mode
npm run dev
# Build the project
npm run build- Follow TypeScript best practices
- Add JSDoc comments for public APIs
- Write meaningful commit messages
- Include tests for new features
- Update documentation as needed
For detailed guidelines, see our Contributing Guide.
Found a bug? We'd love to help fix it! Please report bugs using our bug report template.
- Check if the issue has already been reported
- Try the latest version of the package
- Provide a minimal reproduction example
- Include your environment details
- Clear description of the bug
- Steps to reproduce
- Expected vs actual behavior
- Code example
- Environment information (OS, browser, versions)
We take security seriously. If you discover a security vulnerability, please report it privately.
Do not create a public GitHub issue for security vulnerabilities.
Instead, please email us at: rajkumarrathod414@gmail.com
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if any)
- Initial response: Within 48 hours
- Investigation: Prompt and thorough
- Fix release: As quickly as possible
- Public disclosure: Coordinated with reporter
For more details, see our Security Policy.
Need help? We're here to support you!
- π Documentation: Check our README and examples
- π Issues: Search existing issues
- π§ Email: Contact us directly at rajkumarrathod414@gmail.com
Installation Problems
# Make sure you're using the correct package name
npm install redux-toolkit-state
# For TypeScript support
npm install --save-dev @types/react @types/react-reduxRuntime Errors
// β Wrong - missing provider
function App() {
return <YourApp />;
}
// β
Correct - with provider
import { GlobalReduxProvider } from 'use-toolkit-state';
function App() {
return (
<GlobalReduxProvider>
<YourApp />
</GlobalReduxProvider>
);
}State Access Issues
// β Wrong - accessing non-existent state
const [user, setUser] = useReduxState('user');
// β
Correct - provide initial value
const [user, setUser] = useReduxState('user', { name: '', email: '' });- π§ Email: rajkumarrathod414@gmail.com (24-48 hour response)
- π Issues: GitHub Issues
For detailed support information, see our Support Guide.
- π Contributing - How to contribute to this project
- π Bug Reports - Report a bug
- π Security - Security policy and vulnerability reporting
- π Support - Get help and support
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Redux Toolkit
- Inspired by React's
useStatehook - Made with β€οΈ for the React community
- Special thanks to all our contributors and users
Made with β€οΈ by Rajkumar Rathod
If you find this library helpful, please consider giving it a β on GitHub! useReduxState