Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Converts an RSS feed to JSON with `rss-parser` via React Hooks.

Notifications You must be signed in to change notification settings

gregrickaby/rss-to-json-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSS to JSON Example

Converts an RSS feed to JSON with rss-parser via React Hooks. Built on top of Next.js.

import { useState, useEffect } from "react";
const Parser = require("rss-parser");
const parser = new Parser();

const Homepage = () => {
  const [data, setData] = useState();
  const [error, setError] = useState(false);
  const [loading, setLoading] = useState(true);
  const CORS_PROXY = `https://cors-anywhere.herokuapp.com/`;

  // CHANGE THIS TO MATCH YOUR RSS FEED!
  const feed_url = `https://webdevstudios.com/feed`;

  /**
   * A very basic fetcher. (note the lack of error checking!)
   */
  async function fetchFeed() {
    const feed = await parser.parseURL(CORS_PROXY + feed_url);
    setData(feed);
    setLoading(false);
  }

  /**
   * On mount, fetch the feed.
   */
  useEffect(() => {
    fetchFeed();
  }, []);

  if (error) return <div>Error: {error}</div>;
  if (loading) return <div>Loading...</div>;

  return (
    <div>
      <h1>RSS Feed</h1>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  );
};

export default Homepage;

About

Converts an RSS feed to JSON with `rss-parser` via React Hooks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published