LoginSignup
0

More than 1 year has passed since last update.

【react-hook-form】TypeError: path.split is not a function in reactのエラー対応

Posted at

react-hoook-form

react-hook-form ライブラリを使用時に下記のようなエラーがでたので、その解決方法を記述する

TypeError: path split is not a function

原因

react-hook-form 6と7のバージョン違いによる書き方の違いらしい?↓

参考 stackoverflow

react-hook-form updated to 7.0.0 from 6.X.X and has breaking changes:

You have to replace all ref={register} with {...register('value_name')}

具体例

バージョン

"react-hook-form": "^7.22.5",

エラーバージョン

<div className={styles.root}>
      <form onSubmit={handleSubmit(handleCreate)} className={styles.form}>
        <TextField
          id="outlined-basic"
          label="New Task"
          variant="outlined"
          inputRef={register} //←エラー
          name="taskTitle"
          className={styles.text_field}
        />
      </form>
    </div>

変更後

<div className={styles.root}>
      <form onSubmit={handleSubmit(handleCreate)} className={styles.form}>
        <TextField
          id="outlined-basic"
          label="New Task"
          variant="outlined"
           {...register('taskTitle')}  //変更後
          name="taskTitle"
          className={styles.text_field}
        />
      </form>
    </div>

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
0