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( () => {
		console.log(selectedDate);
		console.log(myCtx);
		// always get initial values here
	});
...

return

....

<IonItem><IonLabel>{myCtx.curTime}</IonLabel></IonItem>
<IonItem><IonLabel>{selectedDate}</IonLabel></IonItem>
//It shows that it has been set. But I cannot get the new value in useIonViewWillLeave
...

I found the solution:

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