Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!