Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added 'create' and 'shallow' imports to docs #2028

Merged
merged 2 commits into from
Sep 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/guides/updating-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
dai-shi marked this conversation as resolved.
Show resolved Hide resolved

type State = {
firstName: string
lastName: string
Expand All @@ -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 })),
Expand All @@ -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>
Expand Down
Loading