我正在从useEffect调用一个函数,在该函数中我正在检查更新的道具,但它显示的是初始道具而不是更新的道具。 但是当我在功能之外管理道具时,它会显示更新的道具,而不是功能内部。
useEffect(() => {
TrackScreen('Sign up');
props
.dispatch(fetchQualifications())
.then((response: any) => {
if (response) {
const qualifications = response.map((data: any) => {
return { value: data.name, label: data.name };
});
setQualificationList(qualifications);
}
})
.catch((error: string) => {
Toast.show({
duration: toastTimer,
text: error,
});
});
const listener = Navigation.events().bindComponent(
{
navigationButtonPressed: ({ buttonId }: NavigationButtonPressedEvent) => {
if (buttonId === 'BACK') {
isFormFilled();
}
},
} as any,
props.componentId,
);
return () => listener.remove();
}, []);
功能:
const isFormFilled = () => {
console.log('props in isForm filled', props);
};