From zbeyens. The source code is available on GitHub.

Plate
PlatePliteEditorsTemplates
GitHub16kGitHub
DiscordDiscord
  • Plate
  • Plitev42
    • Editor API
    • Editor Transforms
    • Node
    • Element
    • Text
    • Path
    • Point
    • Range
    • Location
    • Location Ref
    • Document Change
  • Plate Core
    • Plate Components
    • Plate Editor
    • Plate Plugin
    • Plate Store
    • Plate Controller
  • Plate Utils
  • React Utils
  • cn
  • Floating
  • Resizable

React Utils

PreviousNext

API reference for @udecode/react-utils.

@udecode/react-utils provides small React 19 utilities used across Plate UI packages. It is also re-exported from platejs/react and @udecode/cn.

Installation

pnpm add @udecode/react-utils
pnpm add @udecode/react-utils

Components

Component
Plate Utilscn

On This Page

InstallationComponentsRef And Effect UtilitiesOutside ClickEvent Utility
Build your editor
Production-ready AI template and reusable components.
Get all-access
Contract
PortalBodyPortals children to element ?? document.body and renders children directly when no DOM container exists.
BoxRenders a div, an as component, or a Radix Slot when asChild is true.
TextRenders a span, an as component, or a Radix Slot when asChild is true.
MemoizedChildrenMemoizes a fragment whose only prop is children.

Box and Text receive ref as a normal React 19 prop.

import { Box, PortalBody, Text } from '@udecode/react-utils';
 
export function Status() {
  return (
    <Box className="rounded-md border p-3">
      <Text as="strong">Connected</Text>
      <PortalBody>
        <div role="status">Saved</div>
      </PortalBody>
    </Box>
  );
}
import { Box, PortalBody, Text } from '@udecode/react-utils';
 
export function Status() {
  return (
    <Box className="rounded-md border p-3">
      <Text as="strong">Connected</Text>
      <PortalBody>
        <div role="status">Saved</div>
      </PortalBody>
    </Box>
  );
}

Ref And Effect Utilities

APIBehavior
composeRefs(...refs)Writes the same node to callback refs and ref objects, including ref cleanup callbacks.
useComposedRef(...refs)Returns a memoized composed ref callback.
useStableFn(fn, deps?)Returns a stable function that calls the latest fn.
useIsomorphicLayoutEffectUses useLayoutEffect in the browser and useEffect during SSR.
import * as React from 'react';
import { useComposedRef } from '@udecode/react-utils';
 
export function Input({ ref, ...props }: React.ComponentPropsWithRef<'input'>) {
  const localRef = React.useRef<HTMLInputElement>(null);
 
  return <input ref={useComposedRef(ref, localRef)} {...props} />;
}
import * as React from 'react';
import { useComposedRef } from '@udecode/react-utils';
 
export function Input({ ref, ...props }: React.ComponentPropsWithRef<'input'>) {
  const localRef = React.useRef<HTMLInputElement>(null);
 
  return <input ref={useComposedRef(ref, localRef)} {...props} />;
}

Outside Click

Parameters

    Called when a configured event lands outside every tracked element.

    Removes listeners while true.

    Defaults to ['mousedown', 'touchstart'].

    Ancestor classes that make an event count as inside.

    Explicit refs to observe instead of the returned callback ref.

Returns(element: HTMLElement | null) => void

    A callback ref that registers an element for outside-click detection.

Event Utility

composeEventHandlers(original, next, options?) calls original, then calls next unless the event was prevented and checkForDefaultPrevented is true.