So I am having a problem displaying data from an Api, I am getting this errors
Access to XMLHttpRequest at 'https://swapi.py4e.com/' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
and this one
xhr.js:177 GET https://swapi.py4e.com/ net::ERR_FAILED
and this one createError.js:16 Uncaught (in promise) Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:84)
Any help would be highy appriciated
import React,{useEffect, useState}from 'react'
import axios from 'axios';
function Home() {
const [data, setData] = useState([]);
const apiURL = "https://swapi.py4e.com/";
const fetchData = async () => {
const response = await axios.get(apiURL)
setData(response.data)
}
return (
<div >
<button onClick={fetchData}></button>
</div>
)
}
export default Home