I have that code :
const FetchingApi = (props) => {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(true);
//const [data, loading] = useFetch("myURL");
useEffect(() => {
fetch("myurl.json", { mode: 'no-cors', method: 'GET'}).then(response => {
console.log(response.json())
return response.json()
})
}, [])
return (
<>
<div>
Hello World !
</div>
</>
)
}
export default FetchingApi;
I see in the developer console a 200 code which means it works but I see the variable response.json() such as :
Promise { <state>: "pending" }
<state>: "rejected"
<reason>: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
I don't know why ...
Could you help me please ? I precise that myurl.json contains a JSON file and it works when I put in a JSON Validator