所以,我有这个组件
<ConfirmApplicationPopUp
onConfirm={() => handleConfirmApplication(true)}
/>
每当我尝试运行该函数时(如您所见,该函数已传递给ConfirmApplicationPopUp组件的道具),它告诉我该函数未定义
我的功能在另一个文件中
我这样导入
import handleConfirmApplication from '../shift-details/utils';
功能本身是
export const handleConfirmApplication = async (isInvite) => {
const checkVals =
get(`shift${isInvite ? 'Invite' : ''}.account.accountName`, this.props) === ONBOARDING_ACCOUNT
? omit('payRate', this.props.confirmationCheckValues)
: this.props.confirmationCheckValues;
if (Object.values(checkVals).every(val => val)) {
this.props.onToggleConfirmPopUp();
this.props.onToggleLoadingApply();
try {
if(isInvite) {
await this.handleShiftInviteDecision('ACCEPT')();
}
else {
const shiftId = this.props.shift.id;
const {
data: { updatedShifts },
} = await this.props.updateMyApplication(shiftId, 'APPLY');
this.setState({
updatedShift: updatedShifts.find(({ id }) => id === shiftId),
});
}
} catch (e) {
Alert.alert('Error', parseError(e));
} finally {
this.props.onToggleLoadingApply();
}
} else {
Alert.alert('Error', 'Please confirm all shift requirements');
}
}
为什么会有这种想法发生?我已经检查了与此有关的其他一些主题,但无济于事:(
答案 0 :(得分:2)
这是因为您没有将函数导出为默认值。
如果以以下方式导入它,则它应该可以工作。
import { handleConfirmApplication } from '../shift-details/utils';