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

167
Vistas
I'm comparing my userId with the user._id to get the resume of this user if it's existe but every time the state is full then gets is getting empty

this is my code check it

const [values, setValues] = useState({
    userId: "",
    name: "",
    github: "",
    linkedin: "",
    phone: "",
    project: "",
    project1: "",
    project2: "",
    summary: "",
    title: "",
    college: "",
    languages: "",
    languages1: "",
    languages2: "",
    images: [],
  });
  const [user, setUser] = useState({});
  const [listcvs, setListcvs] = useState([]);

isLoggedIn to get the user logged in

  const handleInput = (event) => {
    let name = event.target.name;
    let value = event.target.value;

    setValues({ ...values, [name]: value });
    
  };

  const isLoggedIn = async () => {
    const options = {
      headers: {
        Authorization: localStorage.getItem("token"),
      },
    };
    try {
      const res = await axios.get("/api/user/auth", options);
      setUser(res.data.user);
      setValues({...values,userId:res.data.user._id})
      // console.log(user);
      // const user = res.data.user
      // return user
      // console.log(res.data.user)
    } catch (error) {
      console.log(error);
    }
  };

  const getAllCvs = async () => {
    try {
      const res = await axios.get("/api/res/getallcv");
      setListcvs(res.data.result);
       
      // console.log(res.data.result)
    } catch (error) {}
  };

i'm using getAllCvs to get all the resumes of user then verifying if the use._id is yje same as userId by using the find()

   setValues(listcvs.find((el) => el.userId === user._id));
   if (values) {
     setTest(false);      
      
   }else{
     setTest(true)
     // setValues({ ...values, userId: user._id });
   }   
 };

 
 useEffect(() => {
   isLoggedIn();

   getAllCvs();

   verify();
 }, []);


 const hundelUpdate = async () => {
    const config = { headers: { "Content-Type": "application/json" } };
    const res = await axios.put("/api/res/update", values, config);
    
    getAllCvs();
   
  };

every time i get the state filled with the resume of user logged in then it get empty for no reason and when i press any key in the keyboard like space the state get filled then empty again this is a screen Shot of the console u can see that my state is full then get empty

about 4 years ago · Juan Pablo Isaza
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