Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
React JS - How this data is set in the setState after promise is resolved
  const [user, setUser] = useState([]);
  useEffect(() => {
    fetch("https://reqres.in/api/users?page=2")
      .then((res) => res.json())
      .then(setUser);
    return () => {
      console.log("CleanUp Code");
    };
  }, []);

How the set State is automatiocally set with this method .then(setUser); --> How the state is set with this method any explanation

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

.then is designed so that you pass a function into it. When the promise resolves, your function will be called and will be passed in the value that the promise resolved to.

So for example, you can create a brand new function, such as (res) => res.json(), and pass that function in to be called when the promise resolves. Or you can pass in a function which already exists, such as setUser. And again, that function will be called when the promise resolves. Calling setUser sets the state.

about 4 years ago · Juan Pablo Isaza Relatório

0

 const [user, setUser] = useState([]);
  useEffect(() => {
    fetch("https://reqres.in/api/users?page=2")
      .then((res) => setUser(res.data))
      .catch(err=>res.json(message: err.message));
    return () => {
      console.log("CleanUp Code");
    };
  }, []);
about 4 years ago · Juan Pablo Isaza Relatório

0

const [user, setUser] = useState([]);
useEffect(() => {
fetch("https://reqres.in/api/users?page=2")
  .then((res) => res.json())
  .then((res) => setUser(res.data))
  .then(setUser);
return () => {
  console.log("CleanUp Code");
};}, [])
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda