mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-24 11:11:29 +08:00
Update docs and sort content
This commit is contained in:
@ -13,7 +13,7 @@ tags:
|
||||
finished: true
|
||||
published: true
|
||||
category:
|
||||
slug: share-my-incorrect-usage-case-of-zustand?lang=en
|
||||
slug: share-my-incorrect-usage-case-of-zustand-en
|
||||
description: Zustand is a state management library that is simple and easy to use. It allows you to access the state via a single selector or shallow comparison to prevent unnecessary re-renders of all components. When the state is updated, you can use `useShallow` to retrieve only the required data. Additionally, you should follow the principle of minimal granularity, only fetching the necessary data instead of using multiple stores to manage different states. Moreover, state that is unrelated to the UI does not need to be accessed via a selector. The correct approach is to directly access the store within the `handleSave` method.
|
||||
toAstro: true
|
||||
date_created: 2025-01-04T11:44:53+08:00
|
||||
@ -115,11 +115,11 @@ const CurrentCamera: React.FC = () => {
|
||||
In the official documentation [Flux-inspired practice - Zustand](https://zustand.docs.pmnd.rs/guides/flux-inspired-practice), it is mentioned that you should use a single store, not multiple stores for different states.
|
||||
|
||||
> **Recommended patterns**
|
||||
>
|
||||
>
|
||||
> **Single store**
|
||||
>
|
||||
>
|
||||
> Your application's global state should be located in a single Zustand store.
|
||||
>
|
||||
>
|
||||
> If you have a large application, Zustand supports splitting the store into slices.
|
||||
|
||||
## Mistake 4: Accessing UI-unrelated state via selectors
|
||||
@ -166,4 +166,4 @@ const ComponentA = () => {
|
||||
|
||||
[master branch notes/zustand learning notes](https://github.com/puxiao/notes/blob/master/zustand%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0.md)
|
||||
|
||||
[How to efficiently manage React local state? This time I chose Zustand! | Bosh's Technical Exploration Notes](https://notes.boshkuo.com/docs/React/zustand#%E7%82%BA%E4%BD%95%E9%81%B8%E6%93%87%E4%BD%BF%E7%94%A8-zustand-)
|
||||
[How to efficiently manage React local state? This time I chose Zustand! | Bosh's Technical Exploration Notes](https://notes.boshkuo.com/docs/React/zustand#%E7%82%BA%E4%BD%95%E9%81%B8%E6%93%87%E4%BD%BF%E7%94%A8-zustand-)
|
||||
|
Reference in New Issue
Block a user