React rss-parser - Parse image

240 Views Asked by At

I'm using the npm react rss-parser to parse an rss file.

I can show the feed title, description, link and also item -> title, description.

I'm unable to parse the data within image. My script doesn't recognise the map that I'm running.

Does anyone have a solution to show the image data?


import React from 'react'
import {render} from 'react-dom';

let Parser = require('rss-parser');
let parser = new Parser();
const CORS_PROXY = "https://cors-anywhere.herokuapp.com/";

class App extends React.Component{
  constructor(props) {
    super(props);
    this.state = { 
      feed: []
     };
  }

  async componentDidMount() {
    const feed = await parser.parseURL(CORS_PROXY + 'https://podcasts.files.bbci.co.uk/p05299nl.rss');
    
    console.log(feed.image.url);  
    console.log(feed.image.title);      
    
      this.setState(feed)
  }
          
  render() {
    return (
    <div>      
      <h2>Blog Posts {this.state.title}</h2>
        <p>{this.state.description}</p>

  
 
{this.state.feed.image && this.state.image.map((image, i) => (
                <div key={i}>
                    <h1>{image.title}</h1>
                </div>
      ))}

  
  
{this.state.items && this.state.items.map((items, i) => (
                <div key={i}>
                    <h2>{items.title}</h2>
                    <a href="">{items.link}</a>
        <p>{items.content}</p>
        <p>{items.pubDate}</p>
        <p>{items.enclosure.url}</p>

                </div>
      ))}
    </div>
    );
  }
}

render(
  <App />, 
  document.getElementById("root")
)

0

There are 0 best solutions below