小编Shi*_*BR2的帖子

如何有条件地禁用输入依赖于“React-hook-form”中的另一个输入值?

我想根据另一个输入值有条件地禁用输入。常见的用例是我们有一个复选框,我们需要禁用/启用相同表单中的另一个输入。我怎样才能用react-hook-form来实现它?我想禁用,而不是提交时的验证。

目前,我正在使用FormControlLabel(material-ui)和react-hook-form。任何帮助将不胜感激。

更新!这是我的想法的一个小演示代码

import { Controller, useForm } from "react-hook-form";
import { FormControlLabel, Checkbox } from "@material-ui/core";

const { control } = useForm({/* some options */});

// Below is render function

<form onSubmit={handleSubmit(onSubmit)}>
  <Controller
  name="checkbox"
  control={control}
  render={({ field: { onChange, value }}) => {
    return (
      <FormControlLabel
        control={
          <Checkbox
            checked={value}
            onChange={e => {
              onChange(e.target.checked);
            }}
          />
        }
        label="Enable text input?"
        labelPlacement="end"
      />
    );
  }}
/>
<Controller
  name="text-input"
  control={control}
  render={({ field: { onChange, value } }) => {
    return …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui react-hook-form

11
推荐指数
1
解决办法
2万
查看次数

vite 库模式下 Tree Shaking 不起作用

我正在使用vite 库模式构建一个库,问题是捆绑器不可进行树摇动。

这里这里、也许这里也有一些相关的主题。

那么,有人有这方面的经验吗?

tree-shaking vite

7
推荐指数
1
解决办法
1万
查看次数