0

Try show in table my array. Array get from AJAX request in Action. I'm using Redux

class IncomeProfile extends Component {
  constructor(props) {
    super(props)
  }

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

render() {
        var elems = this.props.items.course_list;
      console.log(elems);
        return (
          <div>
            <table>
              {elems.map((item) => (

              <tr key={item.course_id}>
                <td>{item.name}</td>
              </tr>

              ))}
            </table>
          </div>
        )
      }

}

const mapDispatchToProps = function(dispatch) {
  return {
      IncomeListProfile: () => dispatch(IncomeProfileList())
      }
  }

const mapStateToProps = function(state) {
  var mystore = state.toArray();
  //console.log(mystore[6]);
  return {
     items: mystore[6]
        };

}
export default connect(mapStateToProps, mapDispatchToProps)(IncomeProfile);

Console.log first print "undefined" then it print this: enter image description here

Try add condition in render method if (elems) { } not helps

1
  • The error message means elems is not definied in the runtime. Hope this helps debugging. Commented Jan 26, 2017 at 10:19

1 Answer 1

1

Make use of the following

var elems = this.props.items['course_list'];
 var copy = Object.assign({}, elems); 
 console.log(elems.course_list);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.