'React Native state is not updating
I'm coding a ToDo app in React Native, and I have the followind function
const [task, setTask] = useState();
const [taskItems, setTaskItems] = useState([]);
const handleAddTask = () => {
if (task !== null && task !== " " && task !== "") {
Keyboard.dismiss();
console.log(taskItems);
setTaskItems([...taskItems, task])
console.log(taskItems);
setTask(null);
storeData(taskItems.toString());
}
}
Both console.logs return the same thing, as if the state is not changin at all!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
