I have a useState list and I want to update it with another list that I created like so:
//my useState
const [friendsToSupervise, setFriendsToSupervise] = useState([{ name: "" }]);
const openMissionModal = () => {
let supervisorsOfSelected = []
///...Adding items to "supervisorsOfSelected"...///
setFriendsToSupervise(supervisorsOfSelected) //trying to set state with "supervisorsOfSelected"
I tried the "useEffect" that a lot of answers mentioned all over, like this:
useEffect(() => {
if (friendsToSupervise == { name: "" }) {
} else {
console.log(friendsToSupervise);
}
}, [friendsToSupervise])
but it does not work (maybe I'm not implementing it right)
EDIT
What is happening is that I can see the previous value of "friendsToSupervise" when I press the button that activates "openMissionModal". On the one side, everything shows up, on the other, the values are not correct
Thank you!