I am trying to access the data I have via external url, but I am not getting any output.
In my solution I want to use React hooks so first, I pointed to the url
const dataInfo = "secretURLwithJSONData";
than I am using useState and useEffect functions in my component
const reactComponent = () => {
const [userData, setUserData] = useState({});
useEffect(() => {
getDataInfo();
}, []);
const getDataInfo = async () => {
const response = await fetch(dataInfo);
const jsonData = await response.json();
setUserData(jsonData);
};
And the last step is that I am pointing out at the data from JSON
<h5 >{userData.name}</h5>
Example of JSON in url:
{
"data": [
{
"attributes": {
"name": "Name"
}
}
]
}
As you can see is is an array of objects, so there are of course more data, but it should give you an idea of the structure.
jsonData in console:
jsonData HERE
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…