Answer the question
In order to leave comments, you need to log in
Why are props not inherited via the redux connect method in the App component?
const state = {
desks: [
{
id: 1,
name: 'Что нужно сделать'
},
{
id: 2,
name: 'В процессе'
}
]
};
function desksReducer(state = [], action) {
switch ( action.type ) {
case 'ADD_DESK':
return [
...state,
action.desk
]
default:
return state;
}
}
function reducer(state = {}, action) {
return {
desks: desksReducer(state.desks, action)
};
}
const store = Redux.createStore(reducer, state);
class App extends React.Component {
constructor(props) {
super(props);
console.log(this.props);
}
render() {
return (
<div class="desk__items">
<button>Add new desk</button>
</div>
);
}
};
ReactRedux.connect(store)(App);
var Provider = ReactRedux.Provider;
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.querySelector('#root'));
Answer the question
In order to leave comments, you need to log in
/* ... */
const mapStateToProps = state => ({
desks: state.desks,
});
const ConnectedApp = ReactRedux.connect(mapStateToProps)(App);
ReactDOM.render(
<ReactRedux.Provider store={store}>
<ConnectedApp />
</ReactRedux.Provider>,
document.querySelector('#root'),
);
Because you do not read the documentation, in which everything is described in detail.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question