Получение состояния из store
import { connect } from "react-redux";
import { userLog } from "../store/actions/index";
const mapStateToProps = state => {
return {
user: state.user
};
};
const mapDispatchToProps = dispatch => {
return {
onUserLog: (user) => dispatch(userLog(user))
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Auth);
Вызываю в этом файлe
console.log(this.props.user); Получаю undefined
Вот мой store
import {
USER_LOG,
} from "../actions/actionTypes";
const initialState = {
user: 'hello'
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case USER_LOG:
return {
...state,
user: state.user.concat({
surname: action.surname,
name: action.name,
patronymic: action.patronymic,
phone: action.phone,
isLoggingIn: action.isLoggingIn
})
};
default:
return state;
}
};
export default reducer;
Конфиг
import { createStore, combineReducers, compose, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import usersReducer from "./reducers/users";
const rootReducer = combineReducers({
users: usersReducer
});
let composeEnhancers = compose;
if (__DEV__) {
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
}
const configureStore = () => {
return createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)));
};
export default configureStore;