import axios from "axios";
import React, { useEffect, useState } from "react";
export default function App() {
const [val, setVal] = useState();
const getAnswer = async () => {
const { data } = await axios("https://yesno.wtf/api");
setVal(data.answer);
};
useEffect(() => {
getAnswer();
}, []);
return <div>{val}</div>;
}
useEffect(() => {
async function fetchData() {
// You can await here
const response = await MyAPI.getData(someId);
// ...
}
fetchData();
}, [someId]); // Or [] if effect doesn't need props or state