Skip to main content

@lexical/react/useLexicalSlotRef

Functions​

useLexicalSlotRef()​

useLexicalSlotRef<T>(editor, nodeKey, slotName): RefCallback<T | null>

Defined in: packages/lexical-react/src/useLexicalSlotRef.ts:32

Experimental

Mounts a host's named slot into the host's React-rendered chrome. The reconciler renders every slot subtree synchronously into a hidden placeholder container; attach the returned ref to the element where the slot should live and this hook moves the container there after each render, before paint, revealing it. It re-runs every render and is idempotent (a React wrapper over the framework-independent mountSlotContainer), so a slot added after the host's first render — or a container recreated by a remove/re-add — is picked up without extra wiring. On unmount (or a nodeKey/slotName change) the previous container is parked back in its host DOM as a hidden placeholder via unmountSlotContainer.

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Parameters​

editor​

LexicalEditor

nodeKey​

string

slotName​

string

Returns​

RefCallback<T | null>