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!