Middleware priority #2389
Replies: 2 comments 2 replies
-
Did you try if both work? Middleware is interesting in Zustand. Implementation-wise, there's nothing for middleware. It's only about types and docs. I think what we have in the middleware tests are the right order. If some patterns were missing we could add them. As for |
Beta Was this translation helpful? Give feedback.
-
Thank you for responding! Good to know about I'm still confused about the other ones -
Does it means that none of the middlewares above impact on or by the
Both work, but I'm trying to understand the impact on mutation. If the pattern recommended is |
Beta Was this translation helpful? Give feedback.
-
I would like to better understand the middleware priority and what's the correct order between the middlewares themselves.
1️⃣
devtools
priorityThe recommendation is to use
devtools
middleware last:However, the two examples shared in the same documentation page show
devtools
wrappingpersist
middleware:I assume that
persist
middleware doesn't mutatesetState
and therefore both optionsdevtools(persist(...))
andpersist(devtools(...))
are OK, but wanted to confirm as the examples are confusing and contradict the recommendation below them.Also, the
middlewareTypes
test is showingdevtools
that is the ost outer middleware:I'm trying to understand it - is it a test to less optimum state and actually trying to mimic the opposite of the recommendation? or maybe leftovers from an older PR?
2️⃣ other middleware priority:
subscribeWithSelector
,immer
etc.Let's say I had 4 middleware (
devtools
,subscribeWithSelector
,persist
,immer
) and wanted to use them in a way that won't introduce bugs due to mutations. What would be the most recommended order?3️⃣ middleware priority with
createWithEqualityFn
Is there any impact on the priority order when using
createWithEqualityFn
withshallow
as it prevents rendering incase deep mutated objects in the store changed?Thank you, appreciate your help on this.
Beta Was this translation helpful? Give feedback.
All reactions