This.refs is an empty object, although it must be set

I have a reaction component that transmits to the t-comb. The shape seems to look good.

return (
  <form className="modal-body-form"
              autoCorrect="off"
              autoCapitalize="none"
              autoComplete="off"
              formMethod="post"
              onSubmit={function(e) {e.preventDefault();}}
            >
     <Form ref="form"
                onChange={this.onFormChange}
                type={eventSchema.struct}
                value={this.state.rawItem}
                options={eventSchema.options}/>
  </form>
);

But in the "onFormChange" method I want to call this.refs.form.getValue(), which usually works. But this time this.refs is an empty object. Any idea why it's empty?

onFormChange: function (rawValue) {
    var modified = false;

    modified = isDataEqual(this.state.itemStoreState.selectedItem || {}, rawValue) === false;

    this.setState({
      rawItem: rawValue,
      modified: modified
    });

    this.refs.form.getValue(); // will automatically trigger the form validation 
}

as information. I am using reaction 0.13.3 with the old createClass syntax. Therefore, it must be properly connected.

+4
source share
2 answers

The error was in the library t-comb-formthat I am using. I had a form inside a form, and the library handled the internal form perfectly, but somehow destroyed the links outside.

0
source

(http://facebook.imtqy.com/react/docs/more-about-refs.html).

, , . DOM node , ReactDOM.findDOMNode "escape-hatch", , , React.

, 0.13. React.findDOMNode(this.refs.form).

+2

Source: https://habr.com/ru/post/1626872/


All Articles