Nyi Nyi Hmue Aung
Nyi Nyi Hmue Aung

Reputation: 726

Data can't be fetched in React-native by using fetch

I am new to react-native. I am trying to fetch some data from the API by using fetch but I am not getting any response back or error. Here is the code

  useEffect(() => {
    fetch("https://randomuser.me/api/?results=8")
      .then((res) => res.json().then((data) => console.log(data)))
      .catch((err) => console.log(err));
  }, []);

What am I doing wrong here??

Upvotes: 0

Views: 800

Answers (1)

yesIamFaded
yesIamFaded

Reputation: 2068

Seems like your parenthesis ")" is set wrong.

 useEffect(() => {
    fetch("https://randomuser.me/api/?results=8")
      .then((res) => res.json())
      .then((data) => console.log(data))
      .catch((err) => console.log(err));
  }, []);

You should try it like this.

Upvotes: 3

Related Questions