Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
euZebe opened this issue Feb 28, 2018 · 2 comments
Closed

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

euZebe opened this issue Feb 28, 2018 · 2 comments
Labels

Comments

@euZebe
Copy link

euZebe commented Feb 28, 2018

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
Copy link
Owner

scniro commented Mar 1, 2018

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 scniro added the bug label Mar 1, 2018
scniro added a commit that referenced this issue Mar 2, 2018
@scniro
Copy link
Owner

scniro commented Mar 2, 2018

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants