@singapore-editor/react
v0.2.15
Published
React components and hooks for mounting and controlling the Singapore editor.
Maintainers
Readme
@singapore-editor/react
React components and hooks for mounting and controlling the Singapore editor.
Part of Singapore. A code editor for the browser that keeps every version.
Install
npm install @singapore-editor/core @singapore-editor/react react@19 react-dom@19Usage
Render this component in your app. Pass the controller's ref to the element that hosts the editor, and give that element a height.
import { useEditor } from '@singapore-editor/react'
export function EditorPanel() {
const controller = useEditor({
document: {
documentId: 'example.ts',
defaultText: 'const value = 1;\n',
languageId: 'typescript',
},
})
const { ref } = controller
return <div ref={ref} style={{ height: '32rem' }} />
}Take ref out of the controller before you pass it to JSX. The React Compiler treats ref={controller.ref} as a ref read and then rejects later render reads of the controller, such as controller.getEditor().
API highlights
useEditor()creates a controller from props.- The controller's
refmounts the view into an element. It needs React 19 ref cleanups. document.defaultTextsets the text when the document opens;document.textwithonTextChangekeeps it in React state.useEditorSelector()subscribes to a state selection.
In the Singapore family
@singapore-editor/core owns the editor view. This optional package adds React lifecycle and state bindings. Choose the other plugins your app needs.
Singapore README · Documentation
License
MIT. License
