i am new in Reactjs and working on nextjs,I have following components (components/Trending.js) which is working with this url "https://jsonplaceholder.typicode.com/users" but whenever i changed url(My custom url which contaning api data) to "https://90d9-2405-201-5002-215b-6c7b-1f41-7a19-f145.in.ngrok.io/serges/api/blogs" then records is not fetching,Here is my code (components/Trending.js)
import React from 'react';
class Trending extends React.Component {
state = {
trending: []
}
componentDidMount() {
axios.get('https://90d9-2405-201-5002-215b-6c7b-1f41-7a19-f145.in.ngrok.io/serges/api/blogs',
)
.then(res => {
const trending = res.data;
this.setState({ trending });
})
}
render() {
return (
<div>
<table className="table table-hover">
{this.state.trending.map((post, index) => {
return (
<tr>
<td>
<h4>{post.name}</h4>
</td>
</tr>
)
})}
</table>
</div>
);
}
}
export default Trending;
import axios from 'axios';
CodePudding user response:
I think you need to import Axios at the top of the file.
CodePudding user response:
You need to check your browser's console and Network tab. Most probably it's the CORS issue