In my react app I'm consuming an API that contains inside the JSON response a field called experience which contains an [{},{}]. In my view, I need to show what inside that tarry and I'm trying to use .map().
For example, I want to show a list of experiences.
The API response getting the Experiences is that:
{
"profileExperiences": [
{
"username": "Jakos",
"experience": [
{
"image": "https://via.placeholder.com/150",
"_id": "5e3975f95fbeec9095ff3d2f",
"role": "Developer",
"company": "Google",
"startDate": "2018-11-09T23:00:00.000Z",
"endDate": "2019-01-05T23:00:00.000Z",
"area": "Copenhagen",
"createdAt": "2020-02-04T13:47:37.167Z",
"updatedAt": "2020-02-04T13:47:37.167Z"
},
{
"image": "https://via.placeholder.com/150",
"_id": "5e3978bf5e399698e20c56d4",
"role": "Developer",
"company": "IBM",
"startDate": "2018-11-09T23:00:00.000Z",
"endDate": "2019-01-05T23:00:00.000Z",
"area": "Copenhagen",
"createdAt": "2020-02-04T13:59:27.412Z",
"updatedAt": "2020-02-04T13:59:27.412Z"
}
],
"experiences_count": 2
}
]
}
I'm interested in what is inside the expereince[] and I want to show that data in a list.
What I tried is this:
const Experiences = () => {
const dispatch = useDispatch();
const { experiences } = useSelector(state => ({
experiences: state.ExperiencesReducer.experiences
}));
console.log("My Exp", experiences.profileExperiences);
useEffect(() => {
dispatch(ExperiencesMiddleware.getAllExperiencesProfile(USERNAME));
}, [dispatch]);
return (
<>
<Container>
<h1>Experience</h1>
{experiences.profileExperiences &&
experiences.profileExperiences.map((E, k) => (
<Row key={k}>
<ul>
<li>{E.experience.role}</li>
</ul>
</Row>
))}
</Container>
</>
);
};
export default Experiences;
I'm able to debug until {E.expereince.role} and the role is undefined but experience instead contains my 2 obj of the array and I cannot figure out how can I show that list.
Do I need an extra mapping for it or need to change approach?