如何添加'redux thunk'和'redux promise'?
我的样板文件与如何添加'redux thunk'和'redux promise'?,redux,redux-thunk,Redux,Redux Thunk,我的样板文件与redux thunk文档的顺序相反。 我的样板文件createStore是参数,但文档使用createStore作为函数。我现在很困惑。如何正确实施存储 我需要使用redux thunk。但我的样板是这样的 import React, {Component} from 'react'; import './App.css'; import SelectTeam from "./components/select_teams"; import reducers from './re
redux thunk
文档的顺序相反。
我的样板文件createStore
是参数,但文档使用createStore
作为函数。我现在很困惑。如何正确实施存储
我需要使用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>
....
如何将redux thunk添加到现有样板文件中?我使用这个。但我不确定这是否正确,但至少是这样。它不会破坏我的应用程序(就目前而言)
从“redux thunk”导入thunk;
...
我用这个。但我不确定这是否正确,但至少是这样。它不会破坏我的应用程序(就目前而言)
从“redux thunk”导入thunk;
...
只需将其传递给applyMiddleware即可
applyMiddleware(promise,thunk)(createStore)
或:
createStore(reducer,applyMiddleware(promise,thunk))
只需将其传递给applyMiddleware即可
applyMiddleware(promise,thunk)(createStore)
或:
createStore(reducer,applyMiddleware(promise,thunk))
我的想法是从项目中删除redux promise
。但我会避免。因为我不知道什么样的情况下我会需要它。我的想法是从项目中删除redux承诺。但我会避免。因为我不知道在什么情况下我会需要它。你怎么知道createStore
和applyMiddleware
的使用模式?你怎么知道createStore
和applyMiddleware
的使用模式?
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)
);
import thunk from 'redux-thunk';
...
<Provider store={createStoreWithMiddleware(reducers, applyMiddleware(thunk))}>