2020-10-26 15:18:23 +03:00
# Recipes
### Using in a typescript project
2022-02-06 08:26:57 +03:00
The recommended way is to use [`@redux-devtools/extension` npm package ](/README.md#13-use-redux-devtools-extension-package-from-npm ), which contains all typescript definitions. Or you can just use `window as any` :
2020-10-26 15:18:23 +03:00
```js
const store = createStore(
rootReducer,
initialState,
(window as any).__REDUX_DEVTOOLS_EXTENSION__ & &
(window as any).__REDUX_DEVTOOLS_EXTENSION__()
);
```
Note that you many need to set `no-any` to false in your `tslint.json` file.
2022-02-06 08:26:57 +03:00
Alternatively you can use type-guard in order to avoid
2020-10-26 15:18:23 +03:00
casting to any.
```typescript
import { createStore, StoreEnhancer } from 'redux';
// ...
type WindowWithDevTools = Window & {
__REDUX_DEVTOOLS_EXTENSION__ : () => StoreEnhancer< unknown , {} > ;
};
const isReduxDevtoolsExtenstionExist = (
arg: Window | WindowWithDevTools
): arg is WindowWithDevTools => {
return '__REDUX_DEVTOOLS_EXTENSION__' in arg;
};
// ...
const store = createStore(
rootReducer,
initialState,
isReduxDevtoolsExtenstionExist(window)
? window.__REDUX_DEVTOOLS_EXTENSION__()
: undefined
);
```
### Export from browser console or from application
```js
store.liftedStore.getState();
```
The extension is not sharing `store` object, so you should take care of that.
### Applying multiple times with different sets of options
2022-02-06 08:26:57 +03:00
We're [not allowing that from instrumentation part ](https://github.com/reduxjs/redux-devtools/blob/main/packages/redux-devtools-extension/src/logOnly.ts ), which can be used it like so:
2020-10-26 15:18:23 +03:00
```js
import { createStore, compose } from 'redux';
2022-02-06 08:26:57 +03:00
import { devToolsEnhancerLogOnly } from '@redux-devtools/extension';
2020-10-26 15:18:23 +03:00
const store = createStore(
reducer,
/* preloadedState, */ compose(
2022-02-06 08:26:57 +03:00
devToolsEnhancerLogOnly({
2020-10-26 15:18:23 +03:00
instaceID: 1,
2021-09-06 23:07:44 +03:00
name: 'Denylisted',
actionsDenylist: '...',
2020-10-26 15:18:23 +03:00
}),
2022-02-06 08:26:57 +03:00
devToolsEnhancerLogOnly({
2020-10-26 15:18:23 +03:00
instaceID: 2,
2021-09-06 23:07:44 +03:00
name: 'Allowlisted',
actionsAllowlist: '...',
2020-10-26 15:18:23 +03:00
})
)
);
```