Answer the question
In order to leave comments, you need to log in
React + Redux, why is no data being passed?
Good afternoon, no data is being transmitted, I'm doing everything right like, but I'm not receiving data:
Создание хранилища и рендеринг компонента
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { ListProject } from "./Components/Projects";
import { rootReducer } from "./Reducers/reducers";
import { createStore } from "redux";
export const store = createStore(
rootReducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
ReactDOM.render(
<Provider store={store}>
<ListProject />
</Provider>,
document.getElementById("root")
);
Редусер
const initialState = {
projects: ["Projects 001"]
};
export function rootReducer(state = initialState) {
return state;
}
Сам компонент с конектом
import React, { Component } from "react";
import { connect } from "react-redux";
export const ListProject = (props) => {
console.log(props.projects);
return <div>Привет из App, { props.projects }!</div>
}
const mapStateToProps = (state) => {
projects: state.projects
}
export default connect(mapStateToProps)(ListProject);
Answer the question
In order to leave comments, you need to log in
Fix:
const mapStateToProps = (state) => {
projects: state.projects
}
const mapStateToProps = (state) => ({
projects: state.projects
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question