0

In the following code the return of JSON.stringify works. When I try to return the data.getOrders Object in the map method I get the Error that data.getOrders object is undefined.

<Query query={GET_ORDERS}>
  {({loading, error, data}) => {
    if(loading) return <div>Loading..</div>;
    if(error) return <div>{error.message}</div>;

    // work
    return <div>{JSON.stringify(data.getOrders)}</div>;

    // doesnt work
    return (
      <ul>
        {data.getOrders.map(order => (
          <li key={order.id}>{order.orderName}</li>
        ))}
      </ul>
    );
  }}
</Query>

How can I return the data object?

4
  • seems like getOrders is not an Array
    – lipp
    Oct 23, 2018 at 11:49
  • but JSON.stringify(data.getOrders) returns: {"id":1,"orderNr":"B-1234-5678","orderName":"Order","__typename":"Order"}
    – Milchgraf
    Oct 23, 2018 at 11:54
  • Oh, okay its not an array.. Thanks!
    – Milchgraf
    Oct 23, 2018 at 11:58
  • when use map function its need to an array but your data is object form.
    – Asif vora
    Oct 23, 2018 at 12:27

0

Your Answer

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

Browse other questions tagged or ask your own question.