Hello stackoverflow I have a problem for react native, I am developing my functionality which allows me to like a post but when I push my id on my array my console is empty. to see my table I have to click a second time on another post so that my first id is displayed in my table.
here is my code
const [liked, setLiked] = useState([])
const arr = []
const Like = (item) => {
if (liked.indexOf(item) === -1) {
const newArr = [...liked]
newArr.push(item)
setLiked(newArr)
console.log(liked)
console.log("ADD ID")
}
}
const removelike = (item) => {
if (liked.indexOf(item) >= 0) {
console.log(liked.indexOf(item))
const DeleteID = liked
DeleteID.splice(item, 1)
setLiked(DeleteID)
console.log("Delete ID")
}
}