비동기 처리를 할 수 있도록 해주는 async/await 알아보기
const users = () => {
getData()
.then(users => {
console.log(users);
return users;
})
.catch(error => {
console.log(error);
});
}
const users = async() => {
console.log(await getData());
return await getData();
}
import axios from "axios";
export default function Nav() {
// 통신 받아 올 nav data
const [nav, setNav] = useState();
useEffect(() => {
const fetchData = async () => {
try {
const result = await axios.get(`public/Data/NavData.json`);
setNavli(result.data.data.nav_data);
} catch (error) {
console.log(error);
}
};
fetchData();
}, []);
}
yarn add @babel/plugin-transform-runtime --dev
yarn add @babel/runtime
yarn add regenerator-runtime
import regeneratorRuntime from "regenerator-runtime";