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