score:1

Accepted answer

In addition to the info lavor gaved, since you use combineReducers, you need to access to state by using your reducer key.

App.js

import React from "react";
import { connect } from "react-redux";
import {loadUsers} from "./action/index";
import UserList from "./UserList";

class App extends React.Component {

  componentDidMount() {
    this.props.loadUsers();
  }

  render() {
    return (
      <div>
        <h1>MYpage</h1>
        <UserList users={this.props.users} />
      </div>
    );
  }
}

function mapStateToProps(state, ownProps) {
  return {
    users: state.IsLoggedReducer
  };
}

export default connect(mapStateToProps, {loadUsers})(App);

I also made some corrections in the reducer file, we need to return the new state with the given payload.

import initialState from "./InitialState";

export default function IsLoggedReducer(state = initialState.user, action) {
  console.log("ap", action.payload);
  switch (action.type) {
    case "LOAD_USER_SUCCESS":
      return [...action.payload]
    default:
      return state;
  }
}

And action file:

import UserApi from "../UserApi";

export function loadUserSuccess(users) {
  return { type: "LOAD_USER_SUCCESS", payload: users };
}
export function loadUsers() {
  return function(dispatch) {
    return UserApi.getAllUsers()
      .then(users => {
        dispatch(loadUserSuccess(users));
      })
      .catch(error => {
        throw error;
      });
  };
}

You can check this codesandbox for the working app.

https://codesandbox.io/s/cranky-colden-v6r6w

score:0

You are not dispatching your action, try to do it in componentDidMount (you need to map dispatch to props first):

App.js

componentDidMount() {
    this.props.loadUsers();
}

// ...

function mapStateToProps(state, ownProps) {
  return {
    user: state.user
  };
}

function mapDispatchToProps(dispatch) {
  return {
    loadUsers: () => dispatch(userActions.loadUsers())
  };
}


export default connect(mapStateToProps, mapDispatchToProps)(App);


Related Query

More Query from same tag