Contents

React

@veditor.eu/react is a controlled component with value and onChange. It is an ES module without JSX and without a build step; React 17+ is a peer dependency (tested with React 18). The package contains no licence logic: pass the key in options.licenseKey as in the plain editor.

VEditor in the React test application

Installation

npm install @veditor.eu/react

Where the editor comes from

The component loads the editor itself (its ES modules and styles) from your server, from assetsUrl, once per page, on first use. The default is /veditor/assets/{version}, the route of the Laravel and Symfony integrations. With Yii2 use the address from VEditorAsset::register($view)->baseUrl; with plain PHP, the public directory where you copied assets/.

The import is marked /* @vite-ignore */ /* webpackIgnore: true */, so Vite and webpack leave it alone and the editor is not bundled into your application.

Usage

import { useState } from 'react';
import { VEditor } from '@veditor.eu/react';

export function ArticleForm({ article, csrfToken }) {
    const [html, setHtml] = useState(article.body);
    return (
        <form method="post">
            <VEditor
                name="content"
                value={html}
                onChange={setHtml}
                options={{ language: 'en', licenseKey: 'VED1.…', ai: { url: '/veditor/ai', csrfToken } }}
                onReady={(editor) => console.log(editor.getStats())}
            />
            <button>Save</button>
        </form>
    );
}
PropDescription
valueHTML content; changing it from outside replaces the editor content (without an event loop)
onChange(html)called after every change
optionseditor options, used when the editor is created; new options need a new key
assetsUrladdress of the editor files, default /veditor/assets/{version}
name, idattributes of the <textarea>, so the component works in a normal form
onReady(editor)the editor instance with the whole API

loadVEditor(assetsUrl) loads the module without a component, for example to create an editor yourself (await module.VEditor.create(element, options)). VERSION and DEFAULT_ASSETS_URL are exported too. TypeScript declarations are included (VEditorProps, VEditorOptions, VEditorInstance).

Something unclear? Send feedback on the documentation.