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

Could you please support React? #274

Closed
jtyjty99999 opened this issue Feb 17, 2016 · 29 comments
Closed

Could you please support React? #274

jtyjty99999 opened this issue Feb 17, 2016 · 29 comments

Comments

@jtyjty99999
Copy link

like https://github.com/securingsincity/react-ace

@aadrian
Copy link

aadrian commented Feb 17, 2016

+1

@josdejong
Copy link
Owner

Yeah that would be cool. If anybody is interested in picking this up please let me know.

@104gogo
Copy link

104gogo commented Mar 15, 2016

+1

6 similar comments
@mxmind
Copy link

mxmind commented Mar 15, 2016

+1

@hegdeashwin
Copy link

+1

@Yonben
Copy link

Yonben commented Aug 31, 2016

+1

@cage1618
Copy link

cage1618 commented Oct 3, 2016

+1

@liuxihua
Copy link

+1

@Adam-Burke
Copy link

+1

@hassankhan
Copy link

hassankhan commented Nov 30, 2016

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 }}
      />
    );
  }
}

@josdejong
Copy link
Owner

Thanks for sharing @hassankhan

@hassankhan
Copy link

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 shouldComponentUpdate() otherwise it'll re-render the tree and you'll lose focus.

@josdejong
Copy link
Owner

Indeed. See also #39 and #337: I'm working on a completely new version of the editor which will have support for patching rather than just replacing the whole JSON document.

@hassankhan
Copy link

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?

@hassankhan
Copy link

Also thanks for your project, @josdejong! Stupidly spent three days trying to create something similar before stumbling across JSON Editor.

@josdejong
Copy link
Owner

Stupidly spent three days trying to create something similar

As long as you're learning and have fun it's no time wasted :)

@nicolaerusan
Copy link

nicolaerusan commented Dec 16, 2016

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:

ERROR in ./~/ajv/lib/refs/json-schema-draft-04.json
Module parse failed: /{myprojectfolder}/node_modules/ajv/lib/refs/json-schema-draft-04.json Unexpected token (2:8)
You may need an appropriate loader to handle this file type.

This thread helped me find the resolution, which was editing the webpack config:
foxhound87/mobx-react-form#1

@josdejong
Copy link
Owner

@nicolaerusan maybe this is something to report at ajv? https://github.com/epoberezkin/ajv/issues

@hassankhan
Copy link

@josdejong It's just something that has to be done to get Webpack to shut up, unfortunately.

@yoiang
Copy link

yoiang commented Mar 22, 2017

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

@FlorianReich1986
Copy link

FlorianReich1986 commented Jun 9, 2017

@nicolaerusan I also had this issue, but could not fix it as described by you
@yoiang I am using your code. Although it is working in general all the styling is gone. Do you know how to fix this?

@yoiang
Copy link

yoiang commented Jun 9, 2017

@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

@veeramarni
Copy link

looks like we can use @next version as it was rewritten in react.

@josdejong
Copy link
Owner

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

@ghost
Copy link

ghost commented Jan 29, 2018

Also TypeScript version of @yoiang gist:
https://gist.github.com/alekseyMusakhahov/1b02ca391545fc9775d406f26c6aa4b7

@welljs
Copy link

welljs commented Jan 29, 2018

@alekseyMusakhahov thanks, just in time

@vankop
Copy link

vankop commented Feb 5, 2018

React uncontrolled component wrapper for jsoneditor

It will be greate if you have any ideas to implement.

Also I faced with ace theme problem, if we set custom theme ace-jsoneditor theme class changing on custom theme class, so min-height become 0. I fixed it with setting min-height to ace_editor

@blowsie
Copy link

blowsie commented Jan 2, 2019

Someone may be able to port the vue-version if needed

@josdejong
Copy link
Owner

👍 thanks for sharing @blowsie

There are also two React examples included: https://github.com/josdejong/jsoneditor/tree/master/examples

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