Answers for "call api using fetch in react js"

3

fetch react

// React fetch with useEffect
 
 useEffect(() => {
    const fetchApi = async () => {
      const response = await fetch(
        `http://api.openweathermap.org/data/2.5/weather?q=${search}&appid=4ea8f345f660789c426b1282d9a41f67`
      );
      const resJson = await response.json();
      setCity(resJson.main);
    };
    fetchApi();
  }, [search]);
Posted by: Guest on November-13-2021
3

How to fetch data from an api react

const fetchData = () => {
return fetch("https://randomuser.me/api/")
      .then((response) => response.json())
      .then((data) => console.log(data));}
Posted by: Guest on June-07-2021

Browse Popular Code Answers by Language