如何添加 `redux-thunk` 和 `redux-promise`?
How to add `redux-thunk` and `redux-promise`?
我的样板文件与 redux-thunk
文档的顺序相反。
我的样板 createStore
是参数,但文档使用 createStore
作为函数。我现在很困惑。我怎样才能正确实施 store
?
我需要使用 redux-thunk。但是我的样板是这样的
import React, {Component} from 'react';
import './App.css';
import SelectTeam from "./components/select_teams";
import reducers from './reducers/index';
import {Provider} from 'react-redux';
import promise from "redux-promise";
import {applyMiddleware, createStore} from 'redux';
import {BrowserRouter, Route, Switch, Redirect} from 'react-router-dom';
import LoginPage from './components/loginPage';
const createStoreWithMiddleware = applyMiddleware(promise)(createStore);
...
render() {
return (
<Provider store={createStoreWithMiddleware(reducers)}>
<BrowserRouter>
....
这是官方文档
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
// Note: this API requires redux@>=3.1.0
const store = createStore(
rootReducer,
applyMiddleware(thunk)
);
如何将 redux-thunk 添加到我现有的样板文件中?
我用这个。但我不确定它是否正确,但至少。它不会破坏我的应用程序(暂时)。
import thunk from 'redux-thunk';
...
<Provider store={createStoreWithMiddleware(reducers, applyMiddleware(thunk))}>
传给applyMiddleware就可以了
applyMiddleware(promise, thunk)(createStore)
或者:
createStore(reducer, applyMiddleware(promise, thunk))
我的样板文件与 redux-thunk
文档的顺序相反。
我的样板 createStore
是参数,但文档使用 createStore
作为函数。我现在很困惑。我怎样才能正确实施 store
?
我需要使用 redux-thunk。但是我的样板是这样的
import React, {Component} from 'react';
import './App.css';
import SelectTeam from "./components/select_teams";
import reducers from './reducers/index';
import {Provider} from 'react-redux';
import promise from "redux-promise";
import {applyMiddleware, createStore} from 'redux';
import {BrowserRouter, Route, Switch, Redirect} from 'react-router-dom';
import LoginPage from './components/loginPage';
const createStoreWithMiddleware = applyMiddleware(promise)(createStore);
...
render() {
return (
<Provider store={createStoreWithMiddleware(reducers)}>
<BrowserRouter>
....
这是官方文档
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
// Note: this API requires redux@>=3.1.0
const store = createStore(
rootReducer,
applyMiddleware(thunk)
);
如何将 redux-thunk 添加到我现有的样板文件中?
我用这个。但我不确定它是否正确,但至少。它不会破坏我的应用程序(暂时)。
import thunk from 'redux-thunk';
...
<Provider store={createStoreWithMiddleware(reducers, applyMiddleware(thunk))}>
传给applyMiddleware就可以了
applyMiddleware(promise, thunk)(createStore)
或者:
createStore(reducer, applyMiddleware(promise, thunk))