Async action
Sử dụng asyncAction tại zustand để thực hiện các action bất đồng bộ
Ví dụ
export const useElementCategories = create<ElementCategoriesStore>(set => ({
status: 'idle',
data: [],
errorMessage: '',
readElementCategories: asyncAction({
set,
service: () => elementCategoriesService.readCategories(),
Error: ReadElementCategoriesError,
}),
}));
API
Name | Type | Default | Description |
---|---|---|---|
set | Zustand | - | SetState của zustand |
service | Function | - | Hàm thực hiện service |
Error? | ErrorConstructor | Error | Exception khi service thực hiện lỗi |
statusKey? | string | status | Key của status |
dataKey? | string | data | Key của data |
errorMessageKey? | string | errorMessage | Key của errorMessage |