edit-vs-json

A JSON editor component for React applications.

See the demo here

Table of Contents

Installation

This module is distributed via npm.

npm install --save edit-vs-json

or

yarn install edit-vs-json

Usage

The Editor component is designed for use in a React application, and has a peer dependency on React.

import { FunctionComponent, useState } from 'react'

import { Editor } from 'edit-vs-json';

const Example: FunctionComponent = () => {
    const [jsonIsValid, setJsonIsValid] = useState(true);

    const handleChange = (currentJsonValue: string, isValid: boolean) => {
      setJsonIsValid(isValid);
    };

    return (
        <Editor
          width="1400px"
          height="400px"
          onChange={handleChange}
          changeDebounceInterval={300}
        />
    );
}

Props

width: string = "100%"

the width of the JSON editor control

height: string = "100%"

the height of the JSON editor control

initValue: string = ""

the initial JSON string value for the Editor

onChange: function(value: string, isValid: boolean)

the JSON editor change event handler, which receives 2 arguments:

changeDebounceInterval: number = 500

the debounce interval in ms for the change event

onKeyEntry: function(key: string, callback: (key?: string | null) => void)

the key entry event handler

keyEntryDebounceInterval: number = 200

the debounce interval in ms for the key entry event

locked: boolean = false

locks the editor when set to true

License

MIT © RichieMillennium