Why returns undefined and state?

Get status from 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);

Cause in this file console.log(this.props.user); Get undefined

Here is my 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;


Config
import { createStore, combineReducers, compose applyMiddleware } from "redux";
import thunk from "redux-thunk";

usersReducer import 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;
June 5th 19 at 21:31
1 answer
June 5th 19 at 21:33
Solution
const mapStateToProps = state => ({
 user: state.users.user
});


Here you have some nonsense:
return {
...state
 user: state.user.concat({
 surname: action.surname,
 name: action.name
 patronymic: action.patronymic,
 phone: action.phone,
 isLoggingIn: action.isLoggingIn
})
};


You what all I want to do?
Save the user state - Harrison_McLaughl commented on June 5th 19 at 21:36
and how you here will help concat?
You are an object transfer method, and the method object to a string will result:
'[object object]'
c complete loss of data. - Lenny.Botsfo commented on June 5th 19 at 21:39
There I just hand-wrote the line. This is to test the functionality of REDUX.
There initially that's what it was
user: [] - Harrison_McLaughl commented on June 5th 19 at 21:42
well if you have questions, ask. - Lenny.Botsfo commented on June 5th 19 at 21:45
Well, I have it calling this method created a brand new array with the user. And overwrite
I react-native study
In parallel trying to use this thing
https://github.com/rt2zz/redux-persist/blob/master... - Harrison_McLaughl commented on June 5th 19 at 21:48
How best to prescribe that if it was not added to the array, and everything overwrite? - Harrison_McLaughl commented on June 5th 19 at 21:51
The entire array - Harrison_McLaughl commented on June 5th 19 at 21:54
you should have a little of the basics of JS to pull, as you have in the initialState there is no array, there you have a object that has a property user which has a string value:
const initialState = {
 user: 'hello'
};
- Lenny.Botsfo commented on June 5th 19 at 21:57
) I wrote at the top. I just 'Hello' wrote to test if I get state - Harrison_McLaughl commented on June 5th 19 at 22:00
data in what form we want to store and how to get going?
Because it is also not an array:
{
 surname: action.surname,
 name: action.name
 patronymic: action.patronymic,
 phone: action.phone,
 isLoggingIn: action.isLoggingIn
}
- Lenny.Botsfo commented on June 5th 19 at 22:03
I think about it. How best to do - Harrison_McLaughl commented on June 5th 19 at 22:06
in the first place, the data is not directly in the action, and in action.payload.
Then your reducer will be:
const initialState = {
 user: {},
};

const reducer = (state = initialState, action) => {
 const { type, payload } = action;

 switch (type) {
 case USER_LOG:
 return payload;
default:
 return state;
}
};
- Lenny.Botsfo commented on June 5th 19 at 22:09

Find more questions by tags Redux