node.js - react-codemirror beforeChange event -
i using react-codemirror npm module follows:
<codemirror classname={classname} value={this.state.code} onbeforechange= {this.onbeforechange} onchange={this.onchange} options={options}/>
the change event works fine can't seem hook beforechange event. know doing wrong?
i have declared handlers in class follows:
onbeforechange(change) { console.log('calling beforechange') } onchange(newcode) { this.setstate({ code: newcode }) }
the beforechange event documented in codemirror docs. https://codemirror.net/doc/manual.html#event_beforechange
thanks
it turns out react-codemirror not expose beforechange event.
however, react-codemirror2 does. switch of library fixed me!
my final callback code:
onbeforechange(cm, change, callonchange) { const options = object.assign({}, default_options, this.props.options) if (options.singleline) { var after = change.text.join('').replace(/\n/g, '') change.update(change.from, change.to, [after]) } callonchange() } onchange(cm, change, code) { this.setstate({ code }) if (this.props.onchange) { this.props.onchange(code) } }
Comments
Post a Comment