Im trying to render and display nested json data but i have some issues this is the code.
import React, { useState, useEffect, useRef } from "react";
//import Moment from 'react-moment';
//import 'moment-timezone';
import moment from 'moment';
const dueTimes = [
{
distance: 6113,
start: {
time: moment().format("2020 7 1, 14, 38, 9"),
address: "University College Dublin, Belfield, Dublin 4, Ireland",
location: { lat: 53.30713120000001, lng: -6.220312 }
},
end: {
time: moment().format("2020 7 1, 15, 2, 8"),
address: "College Green, Dublin 2, Ireland",
location: { lat: 53.3443633, lng: -6.2593112 }
},
steps: [
{
distance: 347,
duration: 244,
start: { lat: 53.30713120000001, lng: -6.220312 },
stop: { lat: 53.309375, lng: -6.2187873 },
mode: "WALKING"
},
{
distance: 5445,
duration: 968,
start: { lat: 53.3094124, lng: -6.218878399999999 },
stop: { lat: 53.3404818, lng: -6.2585706 },
mode: "TRANSIT",
transit: {
dep: {
name: "UCD N11 Entrance, stop 768",
time: moment().format("2020 7 1, 14, 42, 13")
},
arr: {
name: "Dawson Street, stop 792",
time: moment().format("2020 7 1, 14, 58, 21")
},
headsign: "Ongar",
type: "Dublin Bus",
route: "39a"
}
},
{
distance: 321,
duration: 226,
start: { lat: 53.34212669999999, lng: -6.258003599999999 },
stop: { lat: 53.3443633, lng: -6.2593112 },
mode: "WALKING"
}
]
}
];
function Routes() {
return (
<div className="App">
<div className="posts">
{dueTimes.map(item => {
return (
<>
<h4>{item.distance}</h4>
<p>{item.start.time} </p>
</>
)
})}
</div>
</div>
);
}
export default Routes;
How can i render all of this data - i tried to add a nested map too but cant seem to get it to work. Yes im trying to display all of this data. When i tried to access a nested data i get "Error: Objects are not valid as a React child (found: object with keys {lat, lng}). If you meant to render a collection of children, use an array instead."
dueTimes?