React - 비동기

async를 쓸까 axios를 쓸까 고민하다가 기록

Posted by Yan on February 2, 2021

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);
    }