nolimitstore
Version:
A lightweight Redux-like store for React and React Native, with hooks and selector support. Built with TypeScript, no boilerplate, and full reactivity via useSyncExternalStore.
119 lines (84 loc) • 2.3 kB
Markdown
A lightweight, Redux-like global state manager for **React** and **React Native** apps.
Built with **TypeScript**, powered by **hooks**, and optimized with `useSyncExternalStore`.
---
- ✅ No boilerplate — create a store in one line
- 🎯 Select only the state you need with `useStore`
- 🔁 Built-in `useDispatch` for updates
- 📦 React + React Native compatible
- 🧠 Written in TypeScript with full type safety
- 🪶 Tiny and fast
---
```bash
npm install nolimitstore
```
```ts
import { createStore } from 'nolimitstore';
type AppState = {
name: string;
age: number;
};
const store = createStore<AppState>(
{ name: 'Clinton', age: 0 },
(state, action) => {
switch (action.type) {
case 'incremented_age':
return { ...state, age: state.age + 1 };
case 'changed_name':
return { ...state, name: action.nextName };
default:
throw new Error('Unknown action: ' + action.type);
}
}
);
```
```ts
import { StoreProvider } from 'nolimitstore';
function App() {
return (
<StoreProvider store={store}>
<YourAppComponents />
</StoreProvider>
);
}
```
```tsx
import { useStore, useDispatch } from 'nolimitstore';
function Profile() {
const name = useStore(s => s.name);
const age = useStore(s => s.age);
const dispatch = useDispatch();
return (
<>
<Text>{name}</Text>
<Text>{age}</Text>
<Button onPress={() => dispatch({ type: 'incremented_age' })} title="Add Age" />
<Button onPress={() => dispatch({ type: 'changed_name', nextName: 'Essence' })} title="Change Name" />
</>
);
}
```
createStore(initialState, reducer)
Creates the global store.
<StoreProvider store={store}>
Wraps your app to provide context.
useStore(selector)
Access part of the state with a selector.
useDispatch()
Returns the dispatch function to send actions.
• React 18+
• useSyncExternalStore
• TypeScript
• Context API (no external dependencies)
## 📄 License
MIT License
## 👩🏾💻 Author
Created by Clinton Onuoha