I need to update an array passing some data that I have in my asyncstorage, the problem is the data i send in set don't recive the argument i'm passing and in consequence my state isn't print the data i' m trying to pass
const [carList, setCarList] = useState([]);
const getStorage = async () => {
const newCar = await AsyncStorage.getItem('car');
const car = JSON.parse(newCar)
setCarList([...carList, car]);
console.log(carList);
}
The console.log supose to be like:
Array [ Object { "id": 1, "marca": "Alfa Romeo", "modelo": "MiTo", "observaciones": "Color rojo", "placas": "A00-AAA" } ]
but the result i have is
Array []
I recommendo you to use useEffect: