scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

onChange not working #39

Closed stoplion closed 6 years ago

stoplion commented 6 years ago

onChange not working for Controlled

scniro commented 6 years ago

Closing for total absence of detail

stoplion commented 6 years ago

onChange not working for Controlled

stoplion commented 6 years ago

Change this to UnControlled and it will work

scniro commented 6 years ago

@stoplion You're using the component incorrectly. Did you look at the docs? I thought the examples were pretty clear. There's even a demo site!

import {Controlled as CodeMirror} from 'react-codemirror2'

<CodeMirror
  value={this.state.value}
  options={options}
  onBeforeChange={(editor, data, value) => {
    this.setState({value}); // state management here
  }}
  onChange={(editor, data, value) => {
    // downstream callback
  }}
/>
stoplion commented 6 years ago

ok makes sense thx