react-example-unmount

PreviousNext

Properly unmount and remount editor instances.

Docs
prosekitblock

Preview

Loading preview…
registry/src/react/examples/unmount/editor-component.tsx
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'

import { defineBasicExtension } from 'prosekit/basic'
import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/react'
import { useMemo } from 'react'

import ExtensionComponent from './extension-component'

export default function EditorComponent(props: {
  placeholder: string
}) {
  const editor = useMemo(() => {
    return createEditor({ extension: defineBasicExtension() })
  }, [])

  return (
    <ProseKit editor={editor}>
      <div className="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-white dark:bg-gray-950 text-black dark:text-white">
        <div className="relative w-full flex-1 box-border overflow-y-auto">
          <div ref={editor.mount} className="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
        </div>
      </div>
      <ExtensionComponent placeholder={props.placeholder} />
    </ProseKit>
  )
}

Installation

npx shadcn@latest add @prosekit/react-example-unmount

Usage

import { ReactExampleUnmount } from "@/components/react-example-unmount"
<ReactExampleUnmount />