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

Update docs content #2508

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9b23d94
Move docs to old docs
dbritto-dev Apr 24, 2024
b92ba68
Add new docs (WIP)
dbritto-dev Apr 24, 2024
e1c081e
Minor changes
dbritto-dev Apr 24, 2024
8828d67
Minor changes
dbritto-dev Apr 24, 2024
54344d1
Minor fixes
dbritto-dev Apr 24, 2024
90c23c0
Minor fixes
dbritto-dev Apr 24, 2024
aafed40
Minor fixes
dbritto-dev Apr 24, 2024
3144ea8
Minor fixes
dbritto-dev Apr 24, 2024
f1a3834
Minor changes
dbritto-dev Apr 24, 2024
aeb7cde
Minor fixes
dbritto-dev Apr 24, 2024
6c07e5f
Minor fixes
dbritto-dev Apr 24, 2024
60846c7
Minor changes
dbritto-dev Apr 25, 2024
7bdf1cc
Minor changes
dbritto-dev Apr 25, 2024
a4ab750
Minor changes
dbritto-dev Apr 25, 2024
1606977
Minor changes
dbritto-dev Apr 25, 2024
df190b9
Minor changes
dbritto-dev Apr 25, 2024
a5ceba7
Minor changes
dbritto-dev Apr 25, 2024
3637fe7
Minor fixes
dbritto-dev Apr 25, 2024
0746ab1
WIP
dbritto-dev Apr 25, 2024
adec185
Minor changes
dbritto-dev Apr 25, 2024
ee07ba5
WIP
dbritto-dev Apr 27, 2024
626e972
Merge branch 'main' of github.com:dbritto-dev/zustand into update-doc…
dbritto-dev Apr 27, 2024
89771e5
WIP
dbritto-dev Apr 28, 2024
72fec5c
WIP
dbritto-dev Apr 30, 2024
b1f84f8
WIP
dbritto-dev Apr 30, 2024
c4322c5
WIP
dbritto-dev Apr 30, 2024
5834bbf
WIP
dbritto-dev May 3, 2024
cdba318
WIP
dbritto-dev May 4, 2024
ac441ae
WIP
dbritto-dev May 6, 2024
aea4a45
WIP
dbritto-dev May 6, 2024
479da65
WIP
dbritto-dev May 9, 2024
135bc69
WIP
dbritto-dev May 16, 2024
17d433d
WIP
dbritto-dev May 31, 2024
c542900
WIP
dbritto-dev May 31, 2024
c3998cb
Update docs/reference/use-shallow.md
dbritto-dev Jun 2, 2024
27d8afd
Update docs/reference/create-with-equality-fn.md
dbritto-dev Jun 2, 2024
3322bea
WIP
dbritto-dev Jun 2, 2024
32d4be1
Merge branch 'main' of github.com:pmndrs/zustand into update-docs-con…
dbritto-dev Jun 2, 2024
6bd2963
Merge branch 'main' of github.com:pmndrs/zustand into update-docs-con…
dbritto-dev Jun 12, 2024
370dfab
WIP
dbritto-dev Jun 12, 2024
fc886f1
WIP
dbritto-dev Jun 13, 2024
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
5 changes: 5 additions & 0 deletions docs/community/docs-contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Docs Contributors
description:
nav: 301
---
5 changes: 5 additions & 0 deletions docs/community/third-party-libraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Third-party Libraries
description:
nav: 302
---
5 changes: 5 additions & 0 deletions docs/community/versioning-policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Versioning Policy
description:
nav: 303
---
5 changes: 5 additions & 0 deletions docs/community/zustand-videos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Zustand Videos
description:
nav: 300
---
5 changes: 5 additions & 0 deletions docs/learn/async-data-and-data-fetching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Async Data and Data Fetching
description:
nav: 106
---
5 changes: 5 additions & 0 deletions docs/learn/choosing-the-state-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Choosing the State Structure
description: One store, multiple stores, and multiple slices
nav: 104
---
5 changes: 5 additions & 0 deletions docs/learn/colocation-actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Colocating Actions
description:
nav: 105
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Extracting State Logic into a Reducer with Redux and Devtools Middlewares
description:
nav: 112
---
5 changes: 5 additions & 0 deletions docs/learn/isolating-state-between-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Isolating State Between Components
description:
nav: 108
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Listening to Selected Data with SubscribeWithSelector Middleware
description:
nav: 113
---
5 changes: 5 additions & 0 deletions docs/learn/middleware-use-cases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Middleware Use Cases
description:
nav: 114
---
Empty file added docs/learn/nextjs.md
Empty file.
5 changes: 5 additions & 0 deletions docs/learn/persisting-state-with-persist-middleware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Persisting State with Persist Middleware
description:
nav: 111
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Selecting Data and Preventing Re-renders with selectors and equality function
description:
nav: 107
---
5 changes: 5 additions & 0 deletions docs/learn/start-new-project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Start a new project
description: Vanilla, React, and React Native
nav: 102
---
Empty file added docs/learn/testing.md
Empty file.
5 changes: 5 additions & 0 deletions docs/learn/thinking-in-zustand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Thinking in Zustand
description: Motivation, principles, and glossary
nav: 101
---
5 changes: 5 additions & 0 deletions docs/learn/tutorial-tic-tac-toe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: 'Tutorial: Tic-Tac-Toe'
description:
nav: 100
---
5 changes: 5 additions & 0 deletions docs/learn/using-middlewares.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Using Middlewares
description:
nav: 109
---
5 changes: 5 additions & 0 deletions docs/learn/using-typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Using TypeScript
description:
nav: 103
---
5 changes: 5 additions & 0 deletions docs/learn/writing-immutable-update-with-immer-middleware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Writing Immutable Updates with Immer Middleware
description:
nav: 110
---
101 changes: 101 additions & 0 deletions docs/reference/combine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: combine
description:
nav: 200
---

# combine

`combine` middleware lets you create a new state by combining an initial state with additional
state created by a function. This middleware is particularly useful due to infers the state, so you
don't need to type it.

```js
combine(initialState, additionalStateCreator)
```

- [Reference](#reference)
- [Signature](#combine-signature)
- [`setState` function](#setstate-function)
- [`getState` function](#getstate-function)
- [`subscribe` function](#subscribe-function)
- [`storeApi`](#storeapi)
- [Usage](#usage)
- TBD
- [Troubleshooting](#troubleshooting)
- TBD

## Reference

### `combine` Signature

```ts
combine<T, U>(initialState: T, additionalStateCreator: StateCreator<T, [], [], U>): Omit<T, keyof U> & U
dbritto-dev marked this conversation as resolved.
Show resolved Hide resolved
```

#### Parameters

- `initialState`: The value you want the state to be initially. It can be a value of any type,
except a function.
- `additionalStateCreator`: A function that should take [`setState` function](#setstate-function),
[`getState` function](#getstate-function) and [`storeApi`](#storeapi) as arguments. It should
return an additional state based on the initial state.
dbritto-dev marked this conversation as resolved.
Show resolved Hide resolved

#### Returns

`combine` returns a new state that is the result of merging the initial state and the additional
dbritto-dev marked this conversation as resolved.
Show resolved Hide resolved
state.

### `setState` function

The `setState` function lets you update the state to a different value and trigger re-render. You
can pass the next state directly, a next partial state, a function that calculates it from the
previous state, or replace it completely.

#### Parameters

- `nextState`: The value that you want the state to be. It can be a value of any type, but there is
a special behavior for functions.
- If you pass an object as a `nextState`. It will shallow merge `nextState` with the current
state. You can pass only the properties you want to update, this allows for selective state
updates without modifying other properties.
- If you pass a non-object as a `nextState`, make sure you use `replace` as `true` to avoid
unexpected behaviors.
- If you pass a function as a `nextState`. It must be pure, should take current state as its
only argument, and should return the next state. The next state returned by the updater
function face the same restrictions of any next state.
- `replace`: This optional boolean flag controls whether to replace the entire state or merge the
update with the current state.

#### Returns

`setState` function do not have a return value.

### `getState` function

The `getState` function lets you access to the current state. It can be stale on asynchronous
operations.

### `subscribe` function

The `subscribe` function lets you subscribe to state updates. It should take current state and
previous state as arguments.

#### Parameters

- `currentState`: The current state.
- `previousState`: The previous state.

#### Returns

`subscribe` returns a function that lets you unsubscribe.

### `storeApi`

The `storeApi` lets you access to the store API functions like
[`setState` function](#setstate-function), [`getState` function](#getstate-function), and
[`subscribe` function](#subscribe-function).

## Usage

## Troubleshooting
106 changes: 106 additions & 0 deletions docs/reference/create-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: createContext
dbritto-dev marked this conversation as resolved.
Show resolved Hide resolved
description:
nav: 201
---

# createContext ⚛️

`createContext` lets you create a context that components can provider or read a store.

```js
createContext()
```

- [Reference](#reference)
- [Signature](#createcontext-signature)
- [`Provider`](#provider)
- [`useContextStore`](#usecontextstore)
- [`useStoreApi`](#usestoreapi)
- [Usage](#usage)
- [Troubleshooting](#troubleshooting)

## Reference

### `createContext` Signature

```ts
createContext<StoreApi<T>, U = T>(): {
Provider: React.FC<{ createStore: StateCreator<T> }>,
useContextStore: (selectorFn?: (state: T) => U, equalityFn?: (a: T, b: T) => boolean) => U,
useStoreApi: () => StoreApi<T>
}
```

#### Parameters

`createContext` does not take any parameters.

#### Returns

`createContext` returns a context object.

The context object itself does not hold any information. It represents which context other
components read or provide. Typically, you will use `Provider` in components above to specify the
context value. Call `useContexStore` in components below to read it, and call `useStoreApi` in
components bellow to access to store API utilities. The context object has a few properties:

- `Provider` lets you provide the store to components.
- `useContextStore` lets you read the store state.
- `useStoreApi` lets you access to store API utilities

### `selector` function

The `selector` function lets you return data that is based on current state. It should take current
state as its only argument.

### `equality` function

The `equality` function lets you skip re-renders when certain values are unchanged. It should
take the previous state, and its current state as arguments. It should return `true` if the
previous and current states are equal. Otherwise, it should return `false`.

### `Provider`

Wrap your components into a context provider to specify the value of this context for all
components inside:

#### Props

- `createStore`: Lorem ipsum dolor, sit amet consectetur adipisicing elit. Fugit, illum sequi,
nulla a architecto magni eum ex aspernatur laborum numquam neque rerum? Nam quas minus
repudiandae quam accusantium mollitia distinctio.
- `children`: Lorem ipsum dolor sit, amet consectetur adipisicing elit. Obcaecati, iure incidunt
corrupti repellendus accusamus repellat, blanditiis voluptate ex libero soluta id quia, aliquid
nesciunt maxime voluptates alias perspiciatis aperiam autem.

### `useContextStore`

Call `useContextStore` at the top level of your component to read and subscribe to store state.

#### Parameters

- `selectorFn`: A function that lets you return data that is based on current state.
- `equalityFn`: A function that lets you skip re-renders.

#### Returns

`useContextStore` returns current state.

### `useStoreApi`

Call `useStoreApi` at the top level of your component to access store API utilities.

#### Parameters

`useStoreApi` does not take any parameters.

#### Returns

`useStoreApi` returns Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero recusandae
necessitatibus dolorem perspiciatis accusamus vel molestiae qui officiis, iure pariatur ad iste
error dignissimos sequi commodi sapiente quam cumque harum?

## Usage

## Troubleshooting
Loading