JavaScript React Components Managing State and Data Flow Controlled Components

Steven Matos
Steven Matos
9,148 Points

TypeError: Cannot read property 'value' of null

So I am following along the video and its telling me that there is a problem with my line of value.

import React, { Component } from 'react';

class AddPlayerForm extends Component {

state: { value:'' };

handleValueChange = (e) => { this.setState({ value: e.target.value }); }

handleSubmits = (e) => { e.preventDefault(); this.props.addPlayer(this.state.value); }

render(){ return (

  <form onSubmit={this.handleSubmits}>
    <input
      type="text"
      value={this.state.value} // this line has TypeError //
      onChange={this.handleValueChange}
      placeholder="Enter a player's name"
    />
    <input
      type="submit"
      value="Add Player"
    />
  </form>
);

} }

export default AddPlayerForm;

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 47,505 Points

Instead of:

state: {
 value: ''
 };

try:

state = {
    value: ''
 };
Steven Matos
Steven Matos
9,148 Points

thank you very much!