-
-
Save mittalyashu/4182b0cdaa54654e6b9f3e9441831edc to your computer and use it in GitHub Desktop.
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> | |
); | |
} | |
} |
@souru7, you need to convert your RSS feed into JSON format and then fetch the data.
Thanks... Now Working
Hello Mittalyashu,
How to display more than one news and can i get multiple website news at a time.
Thanks in Advance.
Hello Any one.. Please help to get the more then one website news on my react js.
Hey @souru7,
To get the news (data) from multiple website will be same, as you do with single website, fetch the data in RSS format, convert it into JSON and use the above code snippet 🤟🏻.
How do you convert data from RSS format to JSON? Can you do a video on that?
@maggymoller You can use this handy tool www.rss2json.com
please if the rss feed update will the converter update it too when i use it?
Hi mittalyashu, great work this is very helpful. I ran your script but I'm getting cannot read property 'name of undefined. Can you help
Hi how do you display more than one news
Hello Any one.. Please help to get the more then one website news on my react js.
hello, sorou7
Do you have a solution yet..?
@maggymoller Found an old video I created long ago https://www.youtube.com/watch?v=VlgyGFakEO8.
Hope that helps
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?
that's not working for my react js project
I didn't see any news ??