小编iam*_*ord的帖子

在 mantine 形式输入上使用自定义 onChange 事件

我想做一些响应逻辑,当一个值发生变化时,它会触发表单中的其他值发生变化。

我正在使用 mantine 形式,到目前为止我能想到的最好的方法如下:

const onUserChange = (e) => {
   // form.values.acounts.user contains the previous user value
   // e contains the incoming update to it
   form.setFieldValue('other.property.associated.with.user', e);
 }

 <Select label="User"
              data={users}
              {...form.getInputProps(`accounts.user`)}
              onChange={(e) => {
                onUserChange(e);
                form.getInputProps(`accounts.user`).onChange(e)
              }}
      ></Select>
Run Code Online (Sandbox Code Playgroud)

这种方法“似乎”不错,但我不确定是否有更好的方法。有人以前遇到过这个吗?也许一些简洁的回调语法之类的?

reactjs react-hooks react-hook-form mantine

5
推荐指数
1
解决办法
5910
查看次数

标签 统计

mantine ×1

react-hook-form ×1

react-hooks ×1

reactjs ×1