2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【React】Received NaN for the `value` attribute. If this is expected, cast the value to a string.

2
Posted at

はじめに

  • これ関連

問題

  • 以下の処理で""に対してvalueAsNumberをするため、NaNになりエラー
// console.log(e)でe > target > valueの値を確認
const onChangeTime = (e) => {
  setTime(e.target.valueAsNumber)
}

解決

  • 以下で一旦エラーは出なくなる。TypeScriptだと as で型キャスト必要かもしれない
const onChangeTime = (e) => {
  setTime(e.target.valueAsNumber ? e.target.valueAsNumber : "")
}

終わりに

  • フロントの型をあるべき形に整理できるようにしていきたい
2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?