https://github.com/guoyunhe/lowdux
low-cost react side-load state management
https://github.com/guoyunhe/lowdux
Last synced: 4 months ago
JSON representation
low-cost react side-load state management
- Host: GitHub
- URL: https://github.com/guoyunhe/lowdux
- Owner: guoyunhe
- License: gpl-3.0
- Created: 2022-06-19T05:11:15.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-05T13:57:59.000Z (almost 3 years ago)
- Last Synced: 2025-02-12T07:49:43.952Z (4 months ago)
- Language: TypeScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# lowdux
low-cost react side-load state management
## Install
```bash
npm install --save lowdux
```## Usage
### useLowduxState()
Access a state directly
```tsx
import React from 'react';
import { useLowduxState } from 'lowdux';function App() {
const [street, setStreet] = useLowduxState('checkout.address.street');
return (
Street:
setStreet(e.target.value)}
/>
);
}
```### useLowduxSelector()
Remap state with selector function
```tsx
import React from 'react';
import { useLowduxSelector } from 'lowdux';interface Product {
unitPrice: number;
quantity: number;
}function App() {
const totalPrice = useLowduxSelector(
'checkout.products',
(products) =>
products.reduce((prev, curr) => prev + curr.unitPrice * curr.quantity, 0)
);
returnTotal price: {totalPrice};
}
```