An open API service indexing awesome lists of open source software.

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

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