score:6

Accepted answer
addToList() {
   let k = [...this.state.allTasks];
   k.push(this.state.inputValue);
   this.setState({allTasks: k})
}

or
addToList() {
   this.setState({allTasks: [...this.state.allTasks, this.state.inputValue]})
}

score:-1

class App extends Component {
   constructor(props) {
       super(props);
       this.state = {
          inputValue: '',
          allTasks: []
       };

       this.addToList = this.addToList.bind(this);
   }

   addToList(e) {
      if( e && e.preventDefault ) e.preventDefault();
      this.setState({
         allTasks: [...this.state.allTasks, this.state.inputValue]
      });
   }

   render() {
       return (
         <div>
             <h1>کار های خود را مدیریت کنید !</h1>
             <input type="text" placeholder="کار خود را بنویسید ..." value={this.state.inputValue} onChange={ event => this.setState({ inputValue: event.target.value }) } />
             <button onClick={ e => this.addToList(e) }>ثبت کردن</button>
             <hr />
             <ul>
                {
                   this.state.allTasks.map(task => {
                     return <li>{ task }</li>;
                   })
                }
             </ul>
         </div>
       );
   } 
}

Related Query

More Query from same tag