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

docs(issue-1215): restructure top level docs #1222

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions docs/getting-started/comparison.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Comparison
description:
nav: 2
---

⚠️ This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033

## Why zustand over react-redux?

- Simple and un-opinionated
- Makes hooks the primary means of consuming state
- Doesn't wrap your app in context providers
- [Can inform components transiently (without causing render)](recipes#transient-updates-for-often-occurring-state-changes)
7 changes: 7 additions & 0 deletions docs/getting-started/concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Concepts
description:
nav: 1
---

⚠️ This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033
18 changes: 5 additions & 13 deletions docs/introduction.mdx → docs/getting-started/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ description: How to use Zustand
nav: 0
---

:warning: This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033
⚠️ This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033

<p align="center">
<img width="500" src="https://docs.pmnd.rs/zustand-resources/bear.png" />
<img width="600" src="https://github.com/pmndrs/zustand/raw/main/bear.jpg" />
</p>

A small, fast and scalable bearbones state-management solution. Has a comfy api based
on hooks, isn't boilerplatey or opinionated, but still just enough to be explicit
and flux-like.
Expand All @@ -21,7 +22,7 @@ You can try a live demo [here](https://codesandbox.io/s/dazzling-moon-itop4).
npm install zustand
```

### First create a store
## First create a store

Your store is a hook! You can put anything in it: primitives, objects, functions. The `set` function _merges_ state.

Expand All @@ -35,7 +36,7 @@ const useStore = create((set) => ({
}))
```

### Then bind your components, and that's it!
## Then bind your components, and that's it!

Use the hook anywhere, no providers needed. Select your state and the component will re-render on changes.

Expand All @@ -50,12 +51,3 @@ function Controls() {
return <button onClick={increasePopulation}>one up</button>
}
```

#### Why zustand over react-redux?

- Simple and un-opinionated
- Makes hooks the primary means of consuming state
- Doesn't wrap your app in context providers
- [Can inform components transiently (without causing render)](recipes#transient-updates-for-often-occurring-state-changes)

---
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Auto Generating Selectors
nav: 12
nav: 7
---

It is recommended to use selectors when using either the properties or actions from the store.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Calling actions outside a React event handler in pre React 18
nav: 10
nav: 11
---

Because React handles `setState` synchronously if it's called outside an event handler. Updating the state outside an event handler will force react to update the components synchronously, therefore adding the risk of encountering the zombie-child effect.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Flux inspired practice
nav: 3
nav: 6
---

Although zustand is an unopinionated library, here's one of the recommended usages:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Immutable state and merging
nav: 2
nav: 5
---

Like `useState`, we need to update state immutably.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Map and Set Usage
nav: 13
nav: 12
---

You need to wrap Maps and Sets inside an object, and when you want it's update to be reflected (e.g. in React),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Practice with no store actions
nav: 9
nav: 8
---

The recommended usage in the Readme is to colocate actions within the store.
Expand Down
2 changes: 1 addition & 1 deletion docs/testing.mdx → docs/guides/testing.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Testing
description: How to test your new store
nav: 8
nav: 10
---

## Resetting state between tests in **react-dom**
Expand Down
2 changes: 1 addition & 1 deletion docs/typescript.md → docs/guides/typescript.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: TypeScript Guide
nav: 4
nav: 9
---

## Basic usage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Updating nested state object values
nav: 7
nav: 4
---

## Deep nested object
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Persist middleware
nav: 6
nav: 15
---

The persist middleware enables you to store your Zustand state in a storage (e.g. `localStorage`, `AsyncStorage`, `IndexedDB`, etc...) thus persisting it's data.
Expand Down
2 changes: 1 addition & 1 deletion docs/v4-migration.md → docs/migrations/v4-migration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: v4 Migrations
nav: 5
nav: 17
---

If you're not using the typed version (either via TypeScript or via JSDoc) then there are no breaking changes for you and hence no migration is needed either.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: createContext from zustand/context
nav: 11
nav: 16
---

A special `createContext` is provided since v3.5,
Expand Down
4 changes: 2 additions & 2 deletions docs/recipes.mdx → docs/recipes/recipes.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Recipes
description: How to do all you need with Zustand
nav: 1
nav: 13
---

:warning: This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033
⚠️ This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033

## Fetching everything

Expand Down