使用 React-hook-form,无论是否发布,我都无法更改帖子的值

Using React-hook-form and I can't change the value of posts whether it is published or not

现在,我正在做一个创建类似网站的博客的项目,我面临的问题是我无法更改是否使用复选框和 react-hook-form 发布的值。

它在几周前就成功了,所以我认为这是由于 react-hook-form 的更新,但我不知道如何解决它。

我假设下面的代码是要更改的部分。

发布是一个复选框,当检查并提交时,post的值更改为已发布并变为可见。但目前我无法将其发布。它保持为 false,这意味着它即使被选中也不会发布。

<fieldset>
  <input className={styles.checkbox} name="published" type="checkbox" ref={register} />
  <label>Published</label>
</fieldset>

<button type="submit" className="btn-green" disabled={!isDirty || !isValid}>
  Save Changes
</button>

这部分工作正常。 {!isDirty || !isValid}

希望有好心人帮帮我。 谢谢。

这里的问题和你上一个问题类似-你需要修改register的用法以支持v7:

<fieldset>
  <input type="checkbox" {...register("published")} />
  <label>Published</label>
</fieldset>