-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(docs): Issue 1120 docs #1231
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2a0d180
docs: testing documentation review
Exalted100 15d993b
docs: auto-generated-selectors documentation review
Exalted100 a4f4425
docs: auto-generated-selectors documentation review
Exalted100 b0b5f69
docs: flux-inspired-practices documentation review
Exalted100 7d1073e
docs: flux-inspired-practices documentation review
Exalted100 67d4ec5
docs: flux-inspired-practices documentation review
Exalted100 023f7e4
docs: immutable-state-and-merging documentation review
Exalted100 225fc0c
docs: immutable-state-and-merging documentation review
Exalted100 8f475f4
docs: event-handler-in-pre-react-18 documentation review
Exalted100 13f7bc9
docs: ran the yarn run prettier command
Exalted100 1d58fbe
Update docs/guides/flux-inspired-practice.md
dai-shi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ title: Flux inspired practice | |
nav: 6 | ||
--- | ||
|
||
Although zustand is an unopinionated library, here's one of the recommended usages: | ||
Although zustand is an unopinionated library, here are some patterns we recommend: | ||
|
||
- Create one single store | ||
- Define a store only with `set` | ||
- Define dispatch functions at the root level of the store to update one or more store slices | ||
- Create a single store; | ||
- Always use `set` to define a store; | ||
- Define your dispatch functions at the root level of the store to update one or more store slices. | ||
|
||
```js | ||
const useBoundStore = create((set) => ({ | ||
|
@@ -19,11 +19,11 @@ const useBoundStore = create((set) => ({ | |
})) | ||
``` | ||
|
||
See [Splitting the store into separate slices](https://github.com/pmndrs/zustand/blob/main/docs/typescript.md#slices-pattern) for how to define a store with separate slices. | ||
See [Splitting the store into separate slices](https://github.com/pmndrs/zustand/blob/main/docs/guides/typescript.md#slices-pattern) for how to define a store with separate slices. | ||
|
||
## Flux like patterns / "Dispatching" actions | ||
## Flux like patterns / "dispatching" actions | ||
|
||
If you can't live without redux-like reducers, you can define a `dispatch` function on the root level of the store like store | ||
If you can't live without redux-like reducers, you can define a `dispatch` function on the root level of the store like so: | ||
|
||
```typescript | ||
const types = { increase: 'INCREASE', decrease: 'DECREASE' } | ||
|
@@ -46,12 +46,12 @@ const dispatch = useGrumpyStore((state) => state.dispatch) | |
dispatch({ type: types.increase, by: 2 }) | ||
``` | ||
|
||
Or, just use our redux-middleware. It wires up your main-reducer, sets initial state, and adds a dispatch function to the state itself and the vanilla api. Try [this](https://codesandbox.io/s/amazing-kepler-swxol) example. | ||
You could also use our redux-middleware. It wires up your main reducer, sets initial state, and adds a dispatch function to the state itself and the vanilla api. Check [this example](https://codesandbox.io/s/amazing-kepler-swxol). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [no action] Small thing, but these longer links are great for accessibility I believe ("this example" vs previous "this") 👍 |
||
|
||
```typescript | ||
import { redux } from 'zustand/middleware' | ||
|
||
const useReduxStore = create(redux(reducer, initialState)) | ||
``` | ||
|
||
Another way to update the store could be in functions wrapping the state functions. These could also handle side-effects of actions, for example for HTTP-calls. For using Zustand in a none-reactive way see [the readme](https://github.com/pmndrs/zustand#readingwriting-state-and-reacting-to-changes-outside-of-components) | ||
Another way to update the store could be through functions wrapping the state functions. These could also handle side-effects of actions. For example, with HTTP-calls. To use Zustand in a none-reactive way, see [the readme](https://github.com/pmndrs/zustand#readingwriting-state-and-reacting-to-changes-outside-of-components). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[no action] This highlights a "post launch" action. Once the docs are all squared away, we may need to do a pass and update the links to point to the docs themselves rather than back to the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisk-7777 We want to make it work to view docs in github. I believe relative paths should work.