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

MarkdownEditor must be used with a change listener #71

Open
eatyourgreens opened this issue Jun 27, 2018 · 1 comment
Open

MarkdownEditor must be used with a change listener #71

eatyourgreens opened this issue Jun 27, 2018 · 1 comment

Comments

@eatyourgreens
Copy link
Contributor

The default change listener for the editor is NOOP, implying that it's optional. If you don't supply a change listener then the displayed text in the editor doesn't change when you type. In practice, you must supply a change listener, which updates the editor's value prop on change.

@eatyourgreens
Copy link
Contributor Author

Here, the text 'Hello World' cannot be changed in the editor.

<MarkdownEditor value={"Hello World"} />

Setting the value from component state and adding a change listener allows text to be edited:

class HelloWorld extends React.component {
  constructor() {
    this.state = {
      value: 'Hello World'
    };
  }
  onChange(e) {
    const { value } = e.target;
    this.setState({ value });
  }
  render() {
     <MarkdownEditor
      onChange={this.onChange.bind(this)}
      value={this.state.value}
    />
  }
}

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

No branches or pull requests

1 participant