LoginSignup
9
3

More than 5 years have passed since last update.

[React] Warning: `value` prop on `input` should not be null.

Posted at

Webコンソールで警告がでた

Warning: value prop on input should not be null. Consider using the empty string to clear the component or undefined for uncontrolled components.

<input className="form-control"
       type="text"
       name="name"
       value={this.state.company.name}
       onChange={this.onChangeValue}

原因は上記フォームの this.state.company.nameundefined になっていた点
つまり、value属性に 'undefinded' を入れるなということ。

  getInitialState: function() {
    return {
      company: {
        name: ''
      }
    }
  }

getInitialState で初期値で ''(空文字)を入れて、value属性に undefined が入らないようにした。

9
3
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
9
3