I'm using useIonViewDidEnter
hook to fetch data asynchronously from server. For this example, I created a dummy array to show the re rendering behavior. Can someone explain why the data is populated in the console even after I navigate to other tabs. Will this impact the performance of the app? Can this be made better? Any suggestions are appreciated.
const [cars, setCars] = useState([] as any);
const carsList = [{ name: "BMW" }, { name: "Audi" }, { name: "Benz" }];
useIonViewDidEnter(() => {
setCars(carsList);
});
console.log(cars);
I created a working example using CodeSandbox. Could anyone please help?