JsonEditor
JSON checked as it is typed: where the mistake is, in words, and a button that tidies it up.
import { JsonEditor } from '@sypnia/ui/react'
On this page
A test event
Code
import { useState } from 'react';
import { Field, JsonEditor } from '@sypnia/ui/react';
// The comma after «true» is a mistake: it says on which line. Remove it and press «Tidy up».
export default function Body() {
const [json, setJson] = useState('{"event": "order.paid",\n "notify": true,\n}');
return <Field label="Test event"><JsonEditor value={json} onChange={setJson} rows={6} /></Field>;
} When to use it
Use it when
- Test events, settings written as JSON.
Do not use it when
- Settings with a known shape: give them their own fields.
For everyone
- A mistake marks the field invalid and is said with the line number.
Props
| JsonEditor | Type | Default |
|---|---|---|
onChangerequired | (v: string) => void | |
valuerequired | string | |
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
disabled | boolean | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
onRunRuns with Ctrl/⌘ + Enter. | (() => void) | |
placeholder | string | |
readOnly | boolean | |
rowsVisible lines before it scrolls. | number |