import { useFormContext } from 'react-hook-form';
运行结果
const MyButton = () => {
const { reset, setFocus, getValues } = useFormContext<{ step_no: string}>();
useEffect(() => {
setFocus('step_no');
}, [setFocus]);
return (
<div style={{ marginTop: '10px' }}>
<SaveButton type='button'
label='保存'
mutationOptions={{
onSuccess: () => {
reset({ step_no: (parseFloat(getValues('step_no')) + 1).toString() });
window.scrollTo(0, 0);
refresh();
setFocus('step_no');
}
}}
/>
<Button variant='contained' sx={{ ml: 2 }} onClick={() => {
props.handleCreate&&props.handleCreate()
}}>取消</Button>
</div>
)
}
useFormContext
reset({ step_no: (parseFloat(getValues('step_no')) + 1).toString() }); 重新赋值