scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.65k stars 192 forks source link

[uncontrolled] onBeforeChange's third parameter always null #61

Closed euZebe closed 6 years ago

euZebe commented 6 years ago

value parameter seems to always be null in onBeforeChange(editor,_ data, value, next) for an uncontrolled codemirror ; did I miss something ?

import React, { Component } from 'react';
import { UnControlled as CodeMirror } from 'react-codemirror2';

class App extends Component {
  handleBeforeChange = (editor, data, value, next) => {
    console.log('handleBeforeChange', value); // gets null
    next();
  };
  handleChange = (editor, data, value) => {
    console.log('handleChange', value);  // gets the field value
  };
  render() {
    return (
      <div className="App">
        <CodeMirror
          onChange={this.handleChange}
          onBeforeChange={this.handleBeforeChange}
        />
      </div>
    );
  }
}
export default App;
scniro commented 6 years ago

Yikes, it is always null here. I admittedly can not recall at this moment why this is, but I believe it's because we don't actually need the value because we're not managing state. Regardless, the inconsistency remains. I'll likely add value to the cb since an explicit null isn't all that helpful. Thanks for bringing this up 👍

scniro commented 6 years ago

@euZebe Fixed with the 4.0.1 release. Note that value in this callback is actually the old value since we're getting it before a change (in the case of uncontrolled)