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:
Oshri Asulin 2023-09-10 03:13:56 +03:00 committed by GitHub
parent 5062de1310
commit 266e8641b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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>