I want to fetch some data on my React page and it gets the result correctly.
However, regardless of the fetch result, its Promise status is still Pending.
And here's my code:
const config = require("./config.json");
function App() {
const getSongs = (keyword) => {
return fetch(
`https://api.genius.com/search?q=${keyword}&access_token=${config.genius.token}`
)
.then((res) => res.json())
.then((json) => json.response.hits)
.catch((err) => err);
};
console.log(getSongs("faded"));
return <div className="App"></div>;
}
export default App;
I already tried async/await, but it didn't work.
Is there any solution for this situation?