MZaragoza
MZaragoza

Reputation: 10111

React Uncaught SyntaxError: Unexpected token

I am new to react.

I put a debugger in the a function in a component. and I did

this.setState({this.state.ID: null});

and I got back a SyntaxError

React Uncaught SyntaxError: Unexpected token

What am I doing wrong here?

What I am trying to do is to clear the form values on a form.

Search = React.createClass({
  ResetForm: function() {
    // I would like to clear all default values  
    this.setState({
      defaultValues: {
        fields: this.state.fields
      },
    ignoreDefault: false
 });
},

  render: function() {
    return (
      <div className="card-body with-padding-bottom-0">
        <form id={this.formId}>
          <div id="fields" className="usa-grid-full search">
            <Fields ref={(fields) => { this.fields = fields; }} ddl_id='search_card_type' options={ this.getProp('options')} fields={this.getProp('fields')} updateParentState={this.updateStateByField} defaultFieldValues={this.getProp('defaultValues')} ignoreDefault={this.state.ignoreDefault}></Fields>
          </div>

          <div className="usa-grid-full with-margin-top-10 validation-div">
            <div id="search_card_search_button_container" className="usa-width-one-whole">
              <input id="reset_form_button" type="button" name="search" value="Reset Form" onClick={this.ResetForm}/>
            </div>
          </div>
        </form>
      </div>
    );
  }

});

Upvotes: 1

Views: 446

Answers (1)

Doug
Doug

Reputation: 15523

The left side of your object needs to be a primitive, not an expression:

this.setState({ID: null});

Upvotes: 1

Related Questions