P
P
patriot022016-07-24 00:44:27
React
patriot02, 2016-07-24 00:44:27

Not passed to react class, store (redux)?

Not passed to the Cour class (react class) store (Redux).
The console displays just undefined, it doesn't even enter the mapStateToProps function.
What could be the problem? Doesn't throw any errors.

var Cour = React.createClass({
    render: function () {
        console.log(this.props.user)
        return (
            <div>
                <h1>Я мудак</h1>
            </div>)
    }
});

const initialState = {
  user: 'Unknown User'
};
function userstate(state = initialState) {
  return state;
}

var store = Redux.createStore(userstate)

function mapStateToProps (state) {
    console.log('wtf')
    return {
        user: state.user
    }
}

ReactRedux.connect(mapStateToProps)(Cour);

ReactDOM.render(
    <ReactRedux.Provider store={store}>
        <Cour />
    </ReactRedux.Provider>,
    document.getElementById("content")
);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zakhar Orlov, 2016-07-24
@patriot02

var ConnectedCour = ReactRedux.connect(mapStateToProps)(Cour)

<ReactRedux.Provider store={store}>
    <ConnectedCour />
</ReactRedux.Provider>

L
Leonid Prokopchuk, 2016-07-24
@leopro

mapDispatchToPropsforgotten: connect(mapStateToProps, mapDispatchToProps)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question