我认为我已经弄清楚了。我使用了格式化值,并将其放入IF语句中。这是更新的功能:
function NameEditInputCell(props) {
const { error, formattedValue } = props;
const apiRef = useGridApiContext();
const handleBadEmail = async () => {
if (error) {
let oldValue = apiRef.current.setEditCellValue({
id: props.id,
field: "email",
value: formattedValue,
});
apiRef.current.stopCellEditMode({
id: props.id,
field: "email",
value: oldValue,
ignoreModifications: false,
});
}
};
return (
<StyledTooltip open={!!error} title={error}>
<GridEditInputCell onBlur={handleBadEmail} {...props} />
</StyledTooltip>
);
}