React - 비동기
async를 쓸까 axios를 쓸까 고민하다가 기록
get
1
2
3
4
5
const onClick = () => {
axios.get("url").then((response) => {
setData(response.data);
});
};
async
1
2
3
4
5
6
7
8
9
const onClick = async () => {
try {
const response = await axios.get(
'url',
);
setData(response.data);
} catch (e) {
console.log(e);
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
