useParagraphCreate

Returns a function that creates an empty text paragraph on a page and resolves with the new paragraph's block id. To let users place paragraphs by clicking instead, switch the interaction tool to { type: 'addText' } (see useSetInteractionMode).

const createParagraph = useParagraphCreate()

const paragraphId = await createParagraph(pageId, x, y)
  • x and y are the start of the first line's baseline in user space. The paragraph doesn't wrap (its width is 'auto'), and on a rotated page it is turned so that its text reads horizontally on screen.
  • The returned id is session-scoped: don't store it across page reloads.
  • The function is asynchronous because the target page may not be loaded yet.
  • An unknown pageId throws InvalidInputError; with no document loaded, the call throws DocumentNotLoadedError.

To set its wrap width, alignment, and other paragraph properties, pass the returned id to useSetParagraphProps. To fill the created paragraph with text programmatically, pass the returned id to useProgrammaticEditor's getParagraphEditor.