Skip to content

Commit cb25fae

Browse files
committed
docs(changeset): - Support for Zustand-style **slice composition** via SliceCreator utility type.
- Now you can structure your store in a modular, scalable way by composing smaller slices and combining them into a single store. ```ts export type SliceCreator<TStore extends BaseType, TSlice = Partial<TStore>> = ( set: StateSetter<TStore>, get: () => TStore | null, ) => TSlice; ``` **Usage** ``` const useKosha = create<StoreType>((...a) => ({ ...createThemeSlice(...a), ...counterSlice(...a), })); ```
1 parent 821818f commit cb25fae

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

.changeset/beige-regions-relate.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"kosha": patch
3+
---
4+
5+
- Support for Zustand-style **slice composition** via `SliceCreator` utility type.
6+
- Now you can structure your store in a modular, scalable way by composing smaller slices and combining them into a single store.
7+
8+
```ts
9+
export type SliceCreator<TStore extends BaseType, TSlice = Partial<TStore>> = (
10+
set: StateSetter<TStore>,
11+
get: () => TStore | null,
12+
) => TSlice;
13+
```
14+
15+
**Usage**
16+
17+
```
18+
const useKosha = create<StoreType>((...a) => ({
19+
...createThemeSlice(...a),
20+
...counterSlice(...a),
21+
}));
22+
```

lib/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export type StoreCreator<T extends BaseType> = (
4141
get: () => T | null,
4242
) => T & { __get?: () => T | null };
4343

44+
export type SliceCreator<TStore extends BaseType, TSlice = Partial<TStore>> = (
45+
set: StateSetter<TStore>,
46+
get: () => TStore | null,
47+
) => TSlice;
48+
4449
export type Middleware<T extends BaseType> = (storeCreator: StoreCreator<T>) => StoreCreator<T>;
4550

4651
export const create: <T extends BaseType>(

0 commit comments

Comments
 (0)