在浏览器中安装了redux-devtool
还需要再项目中配置composeEnhancers
import {
legacy_createStore as createStore,
applyMiddleware,
compose,
combineReducers,
} from "redux";
import designer from "./reducers/designer";
import thunk from "redux-thunk";
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;
const reducer = combineReducers({
designer,
});
const store = createStore(reducer, composeEnhancers(applyMiddleware(thunk)));
export default store;
搭配ts的时候__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
出现标红
Property ‘REDUX_DEVTOOLS_EXTENSION_COMPOSE’ does not exist on type ‘Window & typeof globalThis’
在global.d.ts
中配置
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
}
}