redux
import { createStore, applyMiddleware, compose } from "redux";
import reducers from "./reducers";
import thunk from "redux-thunk";
const composeEnhancers = process.env.NODE_ENV !== "production" &&
typeof window === "object" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose;
const enhancer = composeEnhancers(applyMiddleware(thunk));
const initialState = {};
const store = createStore(reducers, initialState, enhancer);
export default store;
redux
# NPM
npm install @reduxjs/toolkit
# Yarn
yarn add @reduxjs/toolkit
redux
npm i redux react-redux
aka
redux
// component.js
showNotificationWithTimeout(this.props.dispatch, 'You just logged in.')
// otherComponent.js
showNotificationWithTimeout(this.props.dispatch, 'You just logged out.')
复制代码
|