React Router / Redux-连接的组件未将Redux状态传递给道具

时间:2018-08-01 14:36:57

标签: javascript reactjs redux

我正在将组件连接到redux存储,但仅传递了react-router道具。甚至在<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="extractWAR">false</Set> </Configure> 函数中设置testVar也不起作用。

代码简化:

mapStateToProps

在渲染方法中将//index.js import { createStore, applyMiddleware } from 'redux' import thunk from 'redux-thunk' import {initialState} from './reducers/RootReducer'; const store = createStore(RootReducer,initialState, applyMiddleware(thunk)); ReactDOM.render(( <Provider store={store}> <BrowserRouter> <App /> </BrowserRouter> </Provider> ), document.getElementById('root')); // App.js import Home from './path/to/Home-component' import About from './path/to/About-component' ... <div> <Switch> <Route exact path='/' component={Home}/> <Route path='/uploadsideletters' component={About}/> ... </Switch> </div> ... // About.js ... export default connect(mapStateToProps,mapDispatchToProps)(About); const mapStateToProps = (state) => ({ ...state, testVar: "test" }); const mapDispatchToProps = (dispatch) => ({ // empty for now }); 打印到控制台时,我得到: this.props 我的testVar不在那里。为什么会这样?

1 个答案:

答案 0 :(得分:0)

看似简单,问题是我在REPLACE INTO table2 (value1,value2,date,time) SELECT t1.value1, t1.value2, t1.date, t1.time FROM table1 t1 LEFT JOIN table1 t2 ON (t1.value1 = t2.value1 AND concat(t1.date,' ',t1.time) < concat(t2.date,' ',t2.time)) WHERE t2.date IS NULL; connect(...)之前叫mapStateToProps()

更改连接部分,现在看起来像:

mapDispatchToProps()