React
@0001-labs/aa/react holds AaEditor, the editor as a React component. React is an optional peer dependency: the core does not import it.
import { AaEditor } from '@0001-labs/aa/react'<AaEditor value={markdown} onChange={setMarkdown} toolbar />Every option is a prop: asking AI (prompt), comments, correct and blockPlaceholder among them. Any other prop goes to the editor’s element as an attribute.
The ref
Section titled “The ref”The ref gives the editor and three methods:
| Member | What it does |
|---|---|
editor | The editor itself, or null before it is drawn; see Methods and events |
focus() | Puts the caret in the editor |
undo() | Takes back the last step; true when there was one |
redo() | Puts it back |
const ref = useRef<AaEditorRef>(null)<AaEditor ref={ref} value={markdown} onChange={setMarkdown} /><button onClick={() => ref.current?.undo()}>Undo</button>Keep options stable
Section titled “Keep options stable”Arrays, objects and callbacks that define the editor, atoms, toolbar, commands, blockCommands, menus, drawEquation, comments and blockPlaceholder, should keep their identity between renders: define them outside the component or with useMemo and useCallback. A new one each render makes the editor again.
onChange, onFiles, correct and prompt may be new functions each render: the editor calls the latest one.