Skip to content

Commit

Permalink
docs(issue-1215): restructure top level docs (pmndrs#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisk-7777 authored Aug 25, 2022
1 parent 9cfad3e commit b85f641
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 27 deletions.
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

0 comments on commit b85f641

Please sign in to comment.