Skip to content

Commit 415dd65

Browse files
committed
refactor: clean up "someStore"
1 parent 208ae03 commit 415dd65

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/pagesContent/users/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type Props = {
1010

1111
function RenderUsers({ users }: Props) {
1212
const count = useStore(s => s.count)
13-
const updateCount = useStore(s => s.updateCount)
13+
const updateCount = useStore(s => s.actions.updateCount)
1414

1515
const links = users.map(({ id, name }) => (
1616
<Link

src/stores/someStore/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import type { Store } from './types'
44

55
export const useStore = create<Store>(set => ({
66
count: 0,
7-
updateCount(value) {
8-
set(s => ({ count: s.count + value < 0 ? 0 : s.count + value }))
7+
actions: {
8+
updateCount(value) {
9+
set(s => ({ count: s.count + value < 0 ? 0 : s.count + value }))
10+
},
911
},
1012
}))

src/stores/someStore/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
type Store = {
22
count: number
3+
actions: Actions
4+
}
5+
6+
type Actions = {
37
updateCount(value: number): void
48
}
59

0 commit comments

Comments
 (0)