score:1
Accepted answer
you're calling async
method unlimited time! you need to call it once via useeffect
just when component rendered for first time:
import parser from "rss-parser";
import react, { useeffect } from "react";
function episode() {
const parser = new parser();
const url1 = "https://anchor.fm/s/75abc654/podcast/rss";
const [data, setdata] = react.usestate({});
useeffect(() => {
(async () => {
let data = await parser.parseurl(url1);
console.log(data);
setdata(data);
})();
}, []);
return (
<>
{data.items?.map((item, index) => (
<h1>{item.title}</h1>
))}
</>
);
}
export default function app() {
return <episode />;
}
score:0
just replace your async function with a useeffect
hook like this
useeffect(() => {
async function fetchmyapi() {
let data = await parser.parseurl(url1);
setdata(data);
// console.log(data.title)
// data.items.foreach((item) => {
// console.log(item.title)
//console.log(item.pubdate.slice(5, 17))
//console.log(item.enclosure.url)
// console.log(item.itunes.image)
}
fetchmyapi();
}, []);
this will be executed once every time when your component is loaded on screen
also change the data.item.map
to
{data.items?.map((item, index) => {
return <h1>{item.title}</h1>;
})}
else it will throw error on first render
Source: stackoverflow.com
Related Query
- React-How to display make objects loop in react
- React how to make a call to an API and display an array in an array of objects PokeAPI
- How to make the API call and display it in React JS using React Table and Axios?
- how to make google bots crawl my react website with dynamic urls and display them in google
- React Object of Objects - How to loop through
- Unable to figure out how to highlight or select individual objects in InstancedMesh and display custom HTML tooltip using react three fiber
- How to loop through objects in JSX react
- How to loop through properties of objects inside of an array within a React component?
- How to make a loop request with React using Axios?
- How to display an array of objects in a table in react
- How can I use a loop to make this React component more DRY?
- React Forms : How to make input data as list objects with same input name?
- How can I make different React components display 'inline'?
- How to loop through nested objects in jsx react
- How to loop through an array an put create an array of objects using react and javascript?
- Loop through array of objects and display them in react component
- How to properly iterate or loop through an objects in react
- how to display information by props from an array of objects in a component in React JS
- How to make rest api in to to display data in react js
- How to correctly display an array with objects (from another file) on react page?
- How to make correct loop of JSON in React
- how to make display message in page after click confirm alert in react js
- How to make list of checkboxes controlled in loop in react
- React how to make POST request in For Loop
- React - How to iterate over an array of objects and display each item as a component?
- how to make button to sort array of objects alphabetical javascript react
- How to make a "on/off" button inside a loop react 17
- How to make asynchronous api calls in loop and conditional statements in react js?
- How to save JS objects in array using react native AsyncStorage and display in a Flatlist
- how to display a random value from an array of objects in an React view
More Query from same tag
- Not able to import multiple css without applying in React App
- How to pass paramter in react js URL to get data from api
- There is a problem in making multiple select boxes with react and type scripts
- How to fix "undefined" issue in async call to dispatch in action creator of redux?
- How to import file using path in react?
- IdentityServer4 not working in production
- Error when running next js - TypeError: (0 , react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxDEV) is not a function
- Material UI disable Menu transition
- Adding target=_blank to link tag in button in react does not open new page but disables it?
- nextjs complains about read property of undefined during build
- Cannot delete data in database, despite sending just fine
- Web3.givenProvider returns null
- How to highlight selected button in React?
- How can I setState in a another components useEffect?
- How to route React web app to different link from node Js?
- Automatic vendor chunk with dynamic code splitting
- Two Windows in Electron / React Redux
- ReactJs: Display a list of images from an array of urls
- Testing react component enclosed in withRouter (preferably using jest/enzyme)
- Uncaught TypeError: Cannot read property 'token' of undefined
- PropTypes.instanceOf of functional component not working
- I can't access the object what I want from Poke API
- React-Select input contents disappear when select is not focused
- Promises inside WebWorker (react) throwing babel/webpack error
- antd Switch checked property
- How To Add Props to a Navbar?
- How can I add a scroll to top animation to each closed accordion tab in React?
- Reactjs mui popup
- why do i get the Error Module not found: Can't resolve 'redux'
- React Jest creating error "new Error('...')" exit and fail testing immediately