-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Could you please support React? #274
Comments
+1 |
Yeah that would be cool. If anybody is interested in picking this up please let me know. |
+1 |
6 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
I've managed to integrate JSON Editor into my React project, there were a few difficulties in getting the images to load up via Webpack because of the paths defined in the CSS files. I've worked around it for the moment but a nicer solution would be to share the styles in SCSS and allow overriding certain variables instead IMO. I've also made the following wrapper for use in my project, sharing it here in case it helps anyone else: import { cloneDeep } from 'lodash';
import React, { Component, PropTypes } from 'react';
import JSONEditor from 'jsoneditor';
import './jsoneditor.css';
export default class TreeView extends Component {
static propTypes = {
json : PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
]).isRequired,
height : PropTypes.number,
width : PropTypes.number,
};
static defaultProps = {
};
constructor(props) {
super(props);
this.state = {
json : cloneDeep(props.json),
};
this.editor = null;
this.editorRef = null;
}
componentDidMount() {
this.editor = new JSONEditor(this.editorRef, {
mode : 'tree',
onChange : this.handleChange,
});
this.editor.set(this.props.json);
}
componentWillReceiveProps(nextProps) {
this.editor.set(nextProps.json);
this.setState({
json : nextProps.json,
});
}
componentWillUnmount() {
this.editor.destroy();
}
handleChange = () => {
try {
this.setState({
json : this.editor.get(),
});
} catch (e) {
// HACK! This should propagate the error somehow
console.error(e);
}
}
render() {
const { height, width } = this.props;
return (
<div
id='editor'
ref={(ref) => { this.editorRef = ref; }}
style={{ height, width }}
/>
);
}
} |
Thanks for sharing @hassankhan |
No problem, a few other things I noticed - if you make the component above stateless and manage the state higher up, then you'll need to add some handling for |
That's awesome news!! I'd love the extra hooks, and patch-updating sounds great too. Would it be possible to re-do the CSS in SCSS for v6 as well? |
Also thanks for your project, @josdejong! Stupidly spent three days trying to create something similar before stumbling across JSON Editor. |
As long as you're learning and have fun it's no time wasted :) |
Just got this running in my React project as well. As a quick note for anyone who might hit a similar issue, if you're using WebPack you need to include the JSON Loader appropriately in the webpack config.json file. I kept seeing this issue:
This thread helped me find the resolution, which was editing the webpack config: |
@nicolaerusan maybe this is something to report at ajv? https://github.com/epoberezkin/ajv/issues |
@josdejong It's just something that has to be done to get Webpack to shut up, unfortunately. |
Building on @hassankhan 's earlier post I've put together a little further wrapping. Not everything has been tested yet, let me know if something isn't working or you have any further ideas in the Gist comments! https://gist.github.com/yoiang/6f82874f4fd8fc1a37631dc9cad27172 |
@nicolaerusan I also had this issue, but could not fix it as described by you |
@FlorianReich1986 Yea, we had to manually override it, which was really not optimal. As a result we've since moved onto another JSON editor library |
looks like we can use |
@veeramarni yes that's correct. There is still a build script missing to generate code that can be consumed by a React application, see #393 (help would be welcome). |
Also TypeScript version of @yoiang gist: |
@alekseyMusakhahov thanks, just in time |
React uncontrolled component wrapper for It will be greate if you have any ideas to implement. Also I faced with ace theme problem, if we set custom theme |
Someone may be able to port the vue-version if needed |
👍 thanks for sharing @blowsie There are also two React examples included: https://github.com/josdejong/jsoneditor/tree/master/examples |
like https://github.com/securingsincity/react-ace
The text was updated successfully, but these errors were encountered: