Replies: 1 comment 1 reply
-
Yes. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Just started using Zustand in a project and am very happy thus far. My question is this: what would be the best/recommended practice for retrieving the complete state in a non-component context?
Explanation:
My app is using this for a search functionality. The state (currently) has four elements:
(There are also actions in a separate
type
, both of which are provided to thecreate()
call.)The two values that change the most often are
query
andfilters
. But when the search itself is triggered, the full state is needed for creating the POST content of the API call.The search itself is triggered in a function that lives outside of a component. I can just pass the current state to the function, or I could use
getState()
on the store itself to get the current state from within the function. What I want to avoid, is having a component that is only subscribed to the last two items to re-render if one of the Booleans changes.What are considered to be "best practices" in a case like this?
Edited to Add: I have considered something like this being added to the set of actions when declaring the store (I am making assumptions about what
get()
will return):Would this provide a way to fetch the current state, without having to directly subscribe to each individual element? (Assuming it would even work...)
Beta Was this translation helpful? Give feedback.
All reactions