https://github.com/boenfu/use-box
๐ฆ just a box, nobody use
https://github.com/boenfu/use-box
hooks react react-state-management
Last synced: 2 months ago
JSON representation
๐ฆ just a box, nobody use
- Host: GitHub
- URL: https://github.com/boenfu/use-box
- Owner: boenfu
- License: mit
- Created: 2022-04-28T15:36:16.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-20T01:28:39.000Z (about 4 years ago)
- Last Synced: 2025-12-26T20:10:49.971Z (6 months ago)
- Topics: hooks, react, react-state-management
- Language: TypeScript
- Homepage:
- Size: 37.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# use-box
๐ฆ just a box, nobody use
> ็ฎๅ็่ทจ็ปไปถ็ถๆ็ฎก็
## Example
```ts
interface BoxState {
label: string | undefined;
size: number;
}
const labelBox = createBox(
{
label: undefined,
size: 0,
} as BoxState,
{
async fetch() {
let {label, size} = fetch('https://box.server');
return {
label,
size,
};
},
increase(state, size) {
if (state.size + size > 10) {
return;
}
return {
size: state.size + size,
};
},
},
{
autoResolveDependencies: true,
},
);
export const useLabelBox = labelBox.useBox;
```
```tsx
const Component: FC = () => {
const [{label, size}, {increase}] = useLabelBox();
//
return <>>;
};
```
> // TODO: getter example & docs
## Features
- [x] getter value
- [x] async action ( Support partial state update )
- [x] auto resolve update dependencies ( Power by Proxy )
- [x] types safe
## License
MIT