Created
April 8, 2018 06:54
-
-
Save mittalyashu/4182b0cdaa54654e6b9f3e9441831edc to your computer and use it in GitHub Desktop.
Fetch Data From RSS Feed In React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FetchDataFromRSSFeed extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
recentBlogPost: { | |
name: '', | |
url: '' | |
} | |
} | |
} | |
FetchDataFromRssFeed() { | |
var request = new XMLHttpRequest(); | |
request.onreadystatechange = () => { | |
if (request.readyState == 4 && request.status == 200) { | |
var myObj = JSON.parse(request.responseText); | |
for (var i = 0; i < 1; i ++) { | |
this.setState({ | |
recentBlogPost: { | |
name: myObj.items[i].title, | |
url: myObj.items[i].link | |
} | |
}); | |
} | |
} | |
} | |
request.open("GET", "https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fblog.codecarrot.net%2Ffeed.xml&order_dir=desc&count=30", true); | |
request.send(); | |
} | |
componentDidMount() { | |
{this.FetchDataFromRssFeed()} | |
} | |
render() { | |
return ( | |
<div> | |
Check out our blog: <a target="_blank" href={this.state.recentBlogPost.url}>{this.state.recentBlogPost.name}</a> | |
</div> | |
); | |
} | |
} |
super helpful - thanks for showing me this got an RSS working with this code help. Question is now how do I get more than 1 to show up? Just loop through items?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@maggymoller Found an old video I created long ago https://www.youtube.com/watch?v=VlgyGFakEO8.
Hope that helps