Search code examples
reactjsmodel-view-controlleraxioscrudupdates

Why the Update state doesn't work- Reactjs


I'm working on a personnal project, I wanna update some data using MVC, Reactjs and axios as frontend. can someone help me to fix this issue please. in the console there is no error it doesn't update the selected item, by the way the update op works on backend.

here is the code:

  updateCar(idCars, data) {
      var data = {
        id: this.state.idCars,
        carName: this.state.carName,
        carModel: this.state.carModel
      };

      DataService.update(idCars, data)
      .then(response => {
        this.setState({
          idCars: response.data.idCars,
          carName: response.data.carName,
          carModel: response.data.carModel,
         
          submitted: true
        });
        this.props.history.push('/classement')
      })

          .catch(e => {
            console.log(e);
          });
          
     
      }
<button onClick={ () => this.updateCar()} className="btn btn-success" style={{marginLeft:'35%'}}>
                  Submit
                </button>

Solution

  • check this part where you call the this.updateCar(),

    <button onClick={ () => this.updateCar()} className="btn btn-success" style={{marginLeft:'35%'}}>
                  Submit
                </button>
    

    Don't you suppose to pass the parameters here such as idCars, data?