Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda