小编Ton*_*ins的帖子

组件中的Redux状态

试图弄清楚如何将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)

connect reactjs redux

5
推荐指数
1
解决办法
4099
查看次数

标签 统计

connect ×1

reactjs ×1

redux ×1