PandaText / Docs / React

PandaText for React

The web view inside a React component. No wrapper package needed.

Get started

Install the package, then load your fonts, create a view and set the text. Package sources come with early access.

React

Requires: The web requirements above. The React example uses React 19.

1 Install

Install the web packages. React needs no wrapper package:

npm install @pandatext/core @pandatext/textview

With Vite, exclude both from optimizeDeps as in the Web setup.

2 Create the view

The web view inside a React component. No wrapper package needed.

import { useEffect, useRef } from "react";
import { createPandaText } from "@pandatext/core";
import { PandaTextView } from "@pandatext/textview";
import "@pandatext/textview/PandaTextView.css";

export function Editor({ fontBytes }: { fontBytes: Uint8Array }) {
  const ref = useRef<HTMLDivElement>(null);
  useEffect(() => {
    let view: PandaTextView | undefined;
    let unmounted = false;
    createPandaText().then((textEngine) => {
      if (unmounted || !ref.current) return;
      const fontCollection = textEngine.createCollectionFromFonts([textEngine.createFontFromBytes(fontBytes)]);
      view = new PandaTextView({ textEngine, fontCollection, text: "Hello PandaText" });
      view.mount(ref.current);
    });
    return () => {
      unmounted = true;
      const fontCollection = view?.fontCollection;
      view?.destroy();
      fontCollection?.destroy();
    };
  }, [fontBytes]);
  return <div ref={ref} style={{ height: 400 }} />;
}

API

After setup, every call does the same job on every platform. Open the Editor API for React.

Uses the same API column as Web, Electron, tldraw.