LoginSignup
1
0

react-hook-form isDirtyが立たないのはsetValue shouldDirty: true をしていないから

Posted at

react-hook-formで任意のフォームの状態を更新するときsetValueを使っている箇所はありませんか?

その時にsetValue('targetKey', value)とオプションをつけずに実行するとisDirtyがfalseのまま変わりません。

実際にユーザー操作に近い操作を期待する場合は、setValue('targetKey', value, {shouldDirty: true})とオプションをつけてあげるとisDirty: trueになります。

ref https://github.com/react-hook-form/react-hook-form/issues/72#issuecomment-656500986

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0