-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
65 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Button } from "antd"; | ||
import { useSelector, useTestStore } from "@/stores"; | ||
|
||
export function Test1() { | ||
const { a, addA } = useTestStore(useSelector(["a", "addA"])); | ||
return ( | ||
<div className="flex flex-col gap-4 items-center justify-center border border-teal-400 w-[300px] h-[200px] rounded-sm"> | ||
<Button onClick={addA}>test-1: {a}</Button> | ||
<p>{Math.random()}</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Button } from "antd"; | ||
import { useSelector, useTestStore } from "@/stores"; | ||
|
||
export function Test2() { | ||
const { b, addB } = useTestStore(useSelector(["b", "addB"])); | ||
return ( | ||
<div className="flex flex-col gap-4 items-center justify-center border border-teal-400 w-[300px] h-[200px] rounded-sm"> | ||
<Button onClick={addB}>test-2: {b}</Button> | ||
<p>{Math.random()}</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./selectors"; | ||
export * from "./settings"; | ||
export * from "./test"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { useShallow } from "zustand/shallow"; | ||
import { pick } from "@/utils"; | ||
|
||
export const useSelector = <T extends object, K extends keyof T>(fields: K[]) => | ||
useShallow((state: T) => pick(state, fields)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { create } from "zustand"; | ||
|
||
type State = { | ||
a: number; | ||
addA: () => void; | ||
b: number; | ||
addB: () => void; | ||
}; | ||
|
||
export const useTestStore = create<State>()((set) => { | ||
return { | ||
a: 1, | ||
addA: () => set((state) => ({ a: state.a + 1 })), | ||
b: 2, | ||
addB: () => set((state) => ({ b: state.b + 1 })), | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters