Well, let's go in parts ... I'm trying to consume the data from the Medium API. The problem is that I can't get specific JSON values to display in my component.
I need:
- title
- link
- image (thumbnail)
From each post of the specific medium. API example:
https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mikaeriohana
My code is here:
import React, { useState, useEffect } from 'react';
import axios from 'axios';
function App() {
const [mediumData, setMediumData] = useState([]);
const getData = async () => {
const res = await axios.get(
"https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mikaeriohana"
);
setMediumData(res.data.items);
};
useEffect(() => {
getData();
}, []);
return (
<div className="App">
<h1>Tile 01: </h1>
<p>Link 01: </p>
<img src="" alt="img"/>
</div>
);
}
export default App;
I can with the map () function get all the data at once, but I only need the data from the first post.
When I try to specify the values the following error returns:
{console.log(mediumData.link)}
<h1>Tile 01: {mediumData[0].title}</h1>
<p>Link 01: </p>
My mistakes are always:
undefined
or
TypeError: Cannot read property 'title' of undefined
mediumDatato be set. You can use something likeif (!mediumData || !mediumData.length) { return ''; }