docs: expose enabled devtools options in the documentation (#1326)

This commit is contained in:
François KY 2022-10-01 11:12:24 +02:00 committed by GitHub
parent 3e311520d5
commit d60f0cca7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -379,6 +379,8 @@ import { devtools } from 'zustand/middleware'
const useStore = create(devtools(store))
// Usage with a redux store, it will log full action types
const useStore = create(devtools(redux(reducer, initialState)))
// Disabling devtools (for instance in production build)
const useStore = create(devtools(store, { enabled: false }))
```
devtools takes the store function as its first argument, optionally you can name the store with a second argument: `devtools(store, "MyStore")`, which will be prefixed to your actions.

View File

@ -430,6 +430,12 @@ If an action type is not provided, it is defaulted to "anonymous". You can custo
devtools(..., { anonymousActionType: 'unknown', ... })
```
If you wish to disable devtools (on production for instance). You can customize this setting by providing the `enabled` parameter:
```jsx
devtools(..., { enabled: false, ... })
```
## React context
The store created with `create` doesn't require context providers. In some cases, you may want to use contexts for dependency injection or if you want to initialize your store with props from a component. Because the normal store is a hook, passing it as a normal context value may violate rules of hooks.