试图弄清楚如何将Redux存储状态从Redux拉到我的组件中。我已经将mapStateToProps和“连接”连接起来。但是,当我单击“应用”组件中的按钮时,this.props中没有Redux值。
// React and Redux Const
const { Component } = React;
const { render } = ReactDOM;
const { Provider, connect } = ReactRedux;
const {createStore, combineReducers, bindActionCreators } = Redux;
function tweetReducer(state=[],action) {
if(action.type === 'ADD_TWEET') {
return state.concat({ id: Date.now(), tweet: action.payload})
} else {
return state;
}
}
const rootReducer = combineReducers ({
state: (state = {}) => state,
tweets: tweetReducer
});
class App extends Component{
buttonClicked() {
store.dispatch({type: 'ADD_TWEET', payload: 'This is my first
tweet!'}); …Run Code Online (Sandbox Code Playgroud)