I am using react and redux and I have an object which is store on redux, above screenshot is the data state on redux being map to props inside a component:
class Users extends Component {
constructor(props) {
super(props);
}
componentWillMount() {
this.props.dispatch(fetchUsers());
}
render() {
console.log(this.props.users);
return (
<div className="users">
{React.cloneElement(this.props.children, {
this.props.users
})}
</div>
);
}
}
const mapStateToProps = (state) => ({
users: state.users[0]
});
export default connect(mapStateToProps)(Users);
// reducer
import { createReducer } from '../utils/helpers';
users: createReducer(initialData, {
[FETCH_USERS](state, action) {
return [action.payload, ...state];
}
}),
//saga
function* watchFetchUsers() {
while(true) {
yield take(FETCH_USERS);
try {
const users = yield call(api.fetchUserData);
yield put({ type:FETCH_USERS, payload: users });
} catch (err) {
yield put({ type:SIGNOUT, status: err });
}
}
}
the problem is I can log this data with console.log(this.props.users)
but I can't access the data within with console.log(this.props.users.data) or console.log(this.props.users.data[0]) which came back with error 'data' undefined. Anyone can advice me what the problems are?

usersa array or a object? Are this users fetched asynchronously?dataandincluded- sostate.usersis going to be undefined.