๐Ÿ–ฅFrontEnd/React

axios.get์™€ fetch ์ฐจ์ด

hellohailie 2022. 9. 5. 09:38

 

axios๋Š” response.data๋กœ ๋ฐ›๊ณ , fetch๋Š” response.json()์œผ๋กœ ๋ฐ›๋Š”๋‹ค!

 

axios

 useEffect(() => {
    axios
      .get("http://localhost:3001/user")
      .then((response) => response.data)
      .then((item) => setUserData(item));
  }, []);

 

fetch

 useEffect(() => {
    fetch(`http://localhost:3001/user/`)
      .then((response) => response.json())
      .then((item) => setUserData(item));
  }, []);

 

 

๐Ÿ˜ƒ ์ž˜๋ชป๋œ ๊ฐœ๋… ์ „๋‹ฌ์ด ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์ €์˜ ์„ฑ์žฅ์— ํฐ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค๐Ÿค“