Slate is a unopinionated and completely customizable framework for building rich text editors, providing a foundational set of primitives rather than a monolithic solution. It allows developers to create bespoke editing experiences by composing plugins and extending its core data model. Currently at version `0.124.1` (core `slate` package), it maintains an active development pace with frequent patch and minor releases across its monorepo packages (e.g., `slate-react`, `slate-history`, `slate-dom`). Key differentiators include its pluggable architecture, a robust data model representing content as a nested tree, and deep integration with React for rendering. This approach enables it to be adapted for a wide range of applications, from simple note-taking to complex document authoring systems, by avoiding prescriptive UI/UX decisions.
npm install slateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic Slate editor with React and TypeScript, including custom type definitions and simple bold text rendering. It shows the initialization of the editor with `createEditor`, `withReact`, and `withHistory`, and then renders it using the `Slate` provider and `Editable` component.
Thoroughly review release notes for each minor version upgrade. Expect to refactor code related to editor operations, data models, or plugin APIs. Consult migration guides if available.
Update existing code to use `Location.isPath`, `Location.isPoint`, `Location.isRange`, and `Location.isSpan` where appropriate, especially in performance-critical loops or frequently called functions.
Always initialize your editor instance using `useMemo` to ensure it's stable across renders, as shown in the quickstart. If your editor needs to dynamically change based on props, ensure `editor` is correctly listed as a dependency in relevant `useEffect` hooks, or pass an immutable editor instance.
Ensure you have a `declare module 'slate' { interface CustomTypes { Editor: MyCustomEditor; Element: MyCustomElement; Text: MyCustomText; } }` block in a `.d.ts` file or at the top of your relevant TypeScript file, and that your custom types correctly extend the base Slate types (`ReactEditor`, `BaseElement`, `BaseText`).Wrap your `Editable` component and any custom components utilizing Slate hooks within the `<Slate editor={editor} value={value} onChange={setValue}>` provider component.Add a `default` case to your `switch` statement in `renderElement` and `renderLeaf` to handle unexpected node types gracefully. Ensure all custom element types you define in `CustomTypes` are explicitly handled in `renderElement`.