ianstormtaylor/slate · error · Error

The `useSlateStatic` hook must be used inside the <Slate> co

Error message

The `useSlateStatic` hook must be used inside the <Slate> component's context.

What it means

useSlateStatic() reads the editor from EditorContext, provided only by the <Slate> component. If the hook runs outside that provider the context is null and it throws — by design, to fail fast rather than hand back undefined.

Source

Thrown at packages/slate-react/src/hooks/use-slate-static.tsx:19

import { createContext, useContext } from 'react'
import { Editor } from 'slate'
import { ReactEditor } from '../plugin/react-editor'

/**
 * A React context for sharing the editor object.
 */

export const EditorContext = createContext<ReactEditor | null>(null)

/**
 * Get the current editor object from the React context.
 */

export const useSlateStatic = (): Editor => {
  const editor = useContext(EditorContext)

  if (!editor) {
    throw new Error(
      `The \`useSlateStatic\` hook must be used inside the <Slate> component's context.`
    )
  }

  return editor
}

View on GitHub (pinned to 72a37c701e)

Solutions

  1. Move the component inside the <Slate> subtree, or pass the editor down as a prop for out-of-tree components
  2. Wrap test renders with a <Slate editor={editor} initialValue={...}> helper
  3. For portals, re-provide the context inside portal content

Example fix

// before
const editor = useSlateStatic() // component outside <Slate>

// after
// inside <Slate> subtree:
function MyButton(){ const editor = useSlateStatic(); ... }
// or pass editor as prop from a context-consuming parent
Defensive patterns

Strategy: validation

Validate before calling

// only call inside provider tree
<Slate editor={editor} initialValue={value}>
  <Toolbar />
</Slate>

Prevention

When it happens

Trigger: Calling useSlateStatic() in a component mounted outside <Slate>...</Slate>; testing such a component without wrapping it; portals or separate render roots that bypass the provider tree.

Common situations: Utility components (buttons, menus) rendered outside the editor tree; RTL/Jest tests rendering components bare; refactors promoting a component above the <Slate> provider; micro-frontends mounting widgets separately.

Related errors


AI-assisted analysis of ianstormtaylor/slate@72a37c701e (2026-08-27). Data as JSON: /api/errors/6929bd54f862b415. Report an issue: GitHub.