Skip to content

Instantly share code, notes, and snippets.

@OpakAlex
Created June 14, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OpakAlex/3da528ab8968f09009130d882f91a6a6 to your computer and use it in GitHub Desktop.
Save OpakAlex/3da528ab8968f09009130d882f91a6a6 to your computer and use it in GitHub Desktop.
import React from 'react';
import Editor from 'jsoneditor';
import 'jsoneditor/dist/jsoneditor.css';
export default class JSONEditor extends React.Component {
componentDidMount() {
const options = {
mode: 'tree',
modes: ['code', 'text', 'tree'],
onChange: () => {
this.props.onChange(this.editor.get())
}
}
this.editor = new Editor(this.ref, options)
this.editor.set(this.props.json || {})
}
render() {
const {className} = this.props
return (
<div ref={ref => this.ref = ref} className={className}>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment