Skip to main content

Web: React

@nitrakit/react gives you a hook that creates the editor and two components that show it. It builds on @nitrakit/web: read the JavaScript page for requirements, the license key, media and export. Everything from @nitrakit/web is re-exported.

npm install @nitrakit/react

Show the editor​

useNitrakitEditor creates an editor when the component mounts and frees it when it unmounts. It returns null until the editor is ready; the components show nothing until then.

import { useNitrakitEditor, NitrakitPreview, NitrakitEditor } from '@nitrakit/react'

export function VideoEditor() {
const editor = useNitrakitEditor({
width: 1080,
height: 1920,
onRequest: async (request) => {
if (request.kind === 'addMedia') {
const file = await openMyMediaLibrary()
return file ? { source: (await editor!.addMedia(startUpload(file), file)).source } : null
}
// anything else: the built-in picker
},
})

return (
<>
<NitrakitPreview editor={editor} style={{ height: '60vh' }} />
<NitrakitEditor editor={editor} style={{ height: 320 }} />
</>
)
}
  • Call load() and setLicense() once at start-up, for example in main.tsx before rendering.
  • Both components render a div that the editor fills; size them with style or className.
  • Callbacks (onRequest, onChange, onSelect) always call your latest version, so they can use current state. chrome and layout can change between renders; the size and fonts are read once.
  • Use the returned editor for everything else: editor.addMedia, editor.export, editor.toJson and so on.