mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
fix: added 'create' and 'shallow' imports to docs (#2028)
* add missing import, change name store, change the func in app to two variables * Update docs/guides/updating-state.md --------- Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
This commit is contained in:
parent
5062de1310
commit
266e8641b2
@ -10,6 +10,8 @@ the new state, and it will be shallowly merged with the existing state in the
|
||||
store. **Note** See next section for nested state.
|
||||
|
||||
```tsx
|
||||
import { create } from 'zustand'
|
||||
|
||||
type State = {
|
||||
firstName: string
|
||||
lastName: string
|
||||
@ -21,7 +23,7 @@ type Action = {
|
||||
}
|
||||
|
||||
// Create your store, which includes both state and (optionally) actions
|
||||
const useStore = create<State & Action>((set) => ({
|
||||
const usePersonStore = create<State & Action>((set) => ({
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
updateFirstName: (firstName) => set(() => ({ firstName: firstName })),
|
||||
@ -32,10 +34,8 @@ const useStore = create<State & Action>((set) => ({
|
||||
function App() {
|
||||
// "select" the needed state and actions, in this case, the firstName value
|
||||
// and the action updateFirstName
|
||||
const [firstName, updateFirstName] = useStore(
|
||||
(state) => [state.firstName, state.updateFirstName],
|
||||
shallow
|
||||
)
|
||||
const firstName = usePersonStore((state) => state.firstName)
|
||||
const updateFirstName = usePersonStore((state) => state.updateFirstName)
|
||||
|
||||
return (
|
||||
<main>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user