I want to fetch all data in the JSON where there are two arrays. Rest of the data is correctly fetched, but when it comes to arrays I get "user.category is undefined" or "user.top_media is undefined". How can I fix this?
console.log(response) returns success if I delete HTML's in return statement.
import React from 'react';
import './influencerProfileCard.css';
import { useState, useEffect } from 'react';
import { InstagramEmbed } from 'react-social-media-embed';
const InfluencerProfileCard = () => {
const [user, setUser] = useState([]);
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const x = urlParams.get('influencer');
useEffect(() => {
fetchUsers();
}, []);
async function fetchUsers() {
const response = await
fetch(`http://localhost:3001/api/tours/${x}`)
.then((res) => res.json())
.then((user) => user.data.tour)
console.log(response);
setUser(response);
}
return (
<div className="infProfCard-container">
<div className='infProfCard-info'>
{user.category.map(c => (
<h4>{c}</h4>
))}
</div>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<InstagramEmbed url={user.top_media[0].media_url} width={328} captioned />
</div>
</div>
)
}
export default InfluencerProfileCard
and here is the JSON file when I directly type the API on browser:
here is the console output:


.then((user) => user.tour)instead of.then((user) => user.data.tour)