Ir al contenido

JsonEditor

JSON revisado mientras se escribe: dónde está el error, en palabras, y un botón que lo ordena.

import { JsonEditor } from '@sypnia/ui/react'

En esta página
  1. Un evento de prueba
  2. Cuándo usarlo
  3. Para todos
  4. Props

Un evento de prueba

El JSON tiene un error en la línea 3. Revisa ahí las comas, las comillas y los corchetes.

Código
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>;
}

Cuándo usarlo

Úsalo cuando

  • Eventos de prueba, ajustes escritos en JSON.

No lo uses cuando

  • Ajustes con forma conocida: dales sus propios campos.

Para todos

  • Un error marca el campo como inválido y se dice con el número de línea.

Props

JsonEditorTipoPor defecto
onChangeobligatorio (v: string) => void
valueobligatorio string
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
onRun

Runs with Ctrl/⌘ + Enter.

(() => void)
placeholder string
readOnly boolean
rows

Visible lines before it scrolls.

number
  1. Un evento de prueba
  2. Cuándo usarlo
  3. Para todos
  4. Props

    Busca páginas, secciones y términos