哪个功能submit
或onClick
首先运行?还是会同时运行?
在我的程序中,onClick
函数首先运行,然后运行onSubmit
。但是为什么而且总是这样?
<Form onSubmit={handleSubmit}>
<Form.Field>
<label>Enter new password:</label>
<input
type="text"
name= 'newPassword'
onChange={handleOnChange}
placeholder='New Password'
required
/>
</Form.Field>
<Button type='submit' onClick={handleClick}>Submit</Button>
</Form>
答案 0 :(得分:0)
如果您使用的是Formik,则可以将handleSubmit传递给按钮onClick,并在回调onSubmit中使用您的代码和逻辑
<Form onSubmit={(values) => yourHandleSubmitMethod(values)}>
<Form.Field>
<label>Enter new password:</label>
<input
type="text"
name= 'newPassword'
onChange={handleOnChange}
placeholder='New Password'
required
/>
</Form.Field>
<Button type='submit' onClick={handleSubmit}>Submit</Button>
</Form>