0

After doing a post request from a form I want to update the ui with the form response. so after the success callback I set the response to a prop. handleNewLift. But after that am getting below error.

lift_form.self-ed34db8….js?body=1:28 Uncaught TypeError: Cannot read property 'handleNewLift' of undefined

LiftForm.js.jsx

var LiftForm = React.createClass({

    handleSubmit: function (e) {
        e.preventDefault();
        $.ajax({
            url: "/lifts",
            type: "POST",
            data: {lift: this.state},
            success: function (data) {
                this.props.handleNewLift(data);
                this.setState = this.getInitialState();
            }
        });

    }

Lifts.js.jsx

var Lifts = React.createClass({
    getInitialState: function () {
        return {
            lifts: this.props.data
        }
    },
    getDefaultProps: function () {
        return {
            lifts: []
        }
    },
    addLift: function (lift) {

        lifts = this.state.lifts.slice();
        lifts.push(lift);
        this.setState.lifts = lifts;
    },
    render: function () {
        return (
            <div className="Lifts">
                <h1 className="title">Lifts</h1>
                <LiftForm handleNewLift={this.addLift}/>
                               </div>

        )
    }

});

I cant figure out what is the issue as am learning react.

Abhilash
  • 2,864
  • 3
  • 33
  • 67

0 Answers0