I was following Mosh's react native course when I ran into this problem after trying to delete item from a flatlist using the useState hook it doesn't rerender is there any thing wrong in this code or this is some sort of bug I have I would really appreciate the help this is my code and I'm using handleDelete as an onPress event:
const [messages, setMessages] = useState(initialMessages);
const handleDelete = (message) => {
setMessages(messages.filter(m => m.id != message.id));
}
Edit: I've used mosh's source code but looks like it still doesn't work so I'll try to reinstall react then try again
so Basically I was using react native gesture handler after reinstalling it and expo / react-native I was able to make it work!
const [messages, setMessages] = useState(initialMessages);
const handleDelete = (message) => {
setMessages(messages.filter(m => m.id != message.id));
}
useEffect(()=>{
handleDelete();
},[messages])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.