1

this is my sample

My code is this below. Although I expect one array return from API, it always show two arrays, each field with 10 users in console.

const fetchData = async () => {
  const response = await fetch("https://jsonplaceholder.typicode.com/users");
  const data = await response.json();
  console.log(data);
};
fetchData();
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Aliking66
  • 31
  • 7
  • Can you show what you get in that console.log? I've tested that code and I see one array – Daniel Stoyanoff Aug 26 '22 at 07:31
  • Run that code - it shows only one array. Problem is somewhere else. – Jax-p Aug 26 '22 at 07:33
  • It seems like you are using fetchData in useEffect, in react strictMode useEFfect with empty dependency runs twice in development mode. thats why you are seeing two datas in the console.. – sms Aug 26 '22 at 08:01

0 Answers0