Update typescript.md - middleware order (#2558)

Change in the description of the order of middleware.
This commit is contained in:
Aberratio 2024-05-17 20:36:29 +02:00 committed by GitHub
parent 11cc9c3c5e
commit cae5bb48bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -208,7 +208,7 @@ const useBearStore = create<BearState>()(
)
```
Also, we recommend using `devtools` middleware as last as possible. For example, when you use it with `immer` as a middleware, it should be `immer(devtools(...))` and not `devtools(immer(...))`. This is because`devtools` mutates the `setState` and adds a type parameter on it, which could get lost if other middlewares (like `immer`) also mutate `setState` before `devtools`. Hence using `devtools` at the end makes sure that no middlewares mutate `setState` before it.
Also, we recommend using `devtools` middleware as last as possible. For example, when you use it with `immer` as a middleware, it should be `devtools(immer(...))` and not `immer(devtools(...))`. This is because`devtools` mutates the `setState` and adds a type parameter on it, which could get lost if other middlewares (like `immer`) also mutate `setState` before `devtools`. Hence using `devtools` at the end makes sure that no middlewares mutate `setState` before it.
## Authoring middlewares and advanced usage