I received the dreaded CORS error when hooking up my API. I am using the BeerDB one. I tried the plugin, adding the header, going into index.js
but it does not seem to solve it. Still looking into it, my code for my App.js
is below. It is a React app.
The next thing I can even think of is to refactor my API fetch call to use axios
and use different syntax than currently being used.
import React, {useEffect, useState, Component} from 'react';
import './App.css';
import Beer from './Beer.js';
const App = () => {
const App_Key = "b1322de05886eaf6bdd71b64c52d12b7"
const [beers, setBeers] = useState([]);
useEffect (() => {
getBeers();
}, []);
const getBeers = async () => {
const response = await fetch("http://api.brewerydb.com/v2/?key=b1322de05886eaf6bdd71b64c52d12b7");
const data = await response.json();
console.log(data);
}
return(
<div className="App">
<form>
<input type="text" ></input>
<button type="submit">Search</button>
</form>
{ beers.map(beers => (<Beer /> )) }
</div>
);
}
export default App;