0

my to do list

Hey , When I try to type inside the box , my keyboard input does not reflex into it, is is a simple React to do list , thanks in advance. Here is my code :

class Cont extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      term: '',
      items: []
    };
  }

  onChange = (event)=>{
    this.setState=({term:event.target.value});
  }

  onSubmit = (event) =>{
    event.preventDefault();
    const newItems = [...this.state.items, this.state.term]
    console.log(newItems)
    this.setState({
      term: '',
      items: newItems
    });
  }

  render(){
    return(
      <div>
        <form className="Cont" onSubmit={this.onSubmit}>
          <input value={this.state.term} onChange={this.onChange}/>
          <button>Submit</button>
        </form>
        {this.state.items.map(item => <h3>{item}</h3>)}
      </div>
    );
  }
}
Striped
  • 2,544
  • 3
  • 25
  • 31
amrghazr
  • 13
  • 1
  • 6
  • Your question is still not well constructed. Lay out the problem before the sharing the code. Beyond the ["How to ask"](https://stackoverflow.com/help/how-to-ask) advice, you also need to start by stating the question in a way that focuses on what gap remains _after_ your research. Then describe your strategy thus far, code setup + conditions, and the errors/issues. Also state 'obvious' context that you already know, so that people understand what you have tried. See also [1](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/), [2](https://stackoverflow.com/help/mcve) – New Alexandria Feb 11 '18 at 18:53

1 Answers1

0

You're trying to assign a value to this.setState instead of calling the function. Should be this.setState({ term: event.target.value }); without the =.

mindlis
  • 1,546
  • 11
  • 17