Always get state's initial values with useIonViewWillLeave

I wish to check a context’s value when leaving page, but it always get a default value.

import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonDatetime, IonLabel, IonList, IonItem, IonButton, useIonViewWillLeave } from '@ionic/react';


const [selectedDate, setSelectedDate] = useState(new Date('2022-01-01').toISOString());
const {myCtx, setMyCtx} = React.useContext(MyContext);

useIonViewWillLeave( () => {
		// always get initial values here



//It shows that it has been set. But I cannot get the new value in useIonViewWillLeave

I found the solution:

useIonViewWillLeave( async() => {}, [listenningItems]);