Use Portable Text Editor outside Sanity Studio?

12 replies
Last updated: Sep 4, 2021
user Y
hello! I thought this question would be best directed to you but any help would be appreciated! Is there any way to use the Portable Text (Rich Text Editor) outside of the Sanity Studio?
AI Update

Great question! Yes, you can absolutely use the Portable Text editor outside of Sanity Studio. The Sanity team recently extracted the editor from Studio and released it as a standalone package that you can integrate into any React application.

The Standalone Portable Text Editor

The Portable Text Editor is now available as a reusable React component that you can embed in your own applications. This was a major undertaking by the Sanity team—as discussed in this blog post, they took the editor that was previously hard-coded into Sanity Studio and made it framework-agnostic and customizable.

Key Features

The standalone editor gives you:

  • Full control over styling: You can use any UI library (Tailwind CSS, shadcn/ui, etc.) to style the editor however you want
  • Declarative API: React-friendly approach to rendering text and components
  • Custom behaviors: Set up event handlers for everything from simple text insertion to complex features like slash commands
  • Schema flexibility: Define your own content structure and block types
  • Portable Text format: Content is stored as JSON following the Portable Text specification, which is queryable and serializable

How It Works

The editor handles all the complex behaviors you'd expect from a modern block editor—things like how bold text should extend when you keep typing, proper caret positioning, and keyboard shortcuts. These are all built-in and tested, so you don't have to reinvent the wheel.

The Behavior API is particularly powerful—it's not just for users to customize the editor, but it's actually the foundation for all the core behaviors that ship with the package. This means you can extend or override nearly any aspect of how the editor works.

Rendering Content

Once you have content in Portable Text format, you'll want to render it on your frontend. That's where @portabletext/react comes in. This is a separate package that transforms your Portable Text JSON into React components with custom serializers for styling and behavior.

So to summarize: the Portable Text Editor package lets you create and edit rich content outside of Studio in any React app, while @portabletext/react lets you display that content in your application. Both work independently of Sanity Studio and give you complete control over the editing and rendering experience!

Show original thread
12 replies
Hi User! No, unfortunately you cannot publicly expose the Portable Text editor.
It’s correct what
user M
says that the editor is currently dependent on the studio, but may I ask what the use case is? We have plans to open source it without the studio dependencies (no ETA).
Thanks for the responses! I have a school district using the studio for about a year. Their needs have grown to where they will like to have many many editors but these editors only need a very small subset of the total dataset. I planned on building a small interface with authentication then pull the data from sanity based on the users needs. It would be nice to be able to give them the Rich Text Editor within that interface.
Aha. I see. You can also build a custom studio for them with the subset, deploy that to Netlify or something, and give them the URL to that.
Ah so you can also filter the results of what items come back within a collection?
Yup!
Cool! But each editor would need a seat in the project correct?
Yes, that’s correct
Got it. Ok cool I will look more into it. Would be great to see Portable Text Editor out in OS. Or maybe even a way to allow other editors like Editor.js or Slate to be able to output Potable Text Format for simple editing experiences outside of the Studio.
user Y
is there a limit to how many paid datasets you can create?
Isn't Sanity Rich Text Editor based on Slate? (cause I was under the impression that it was).

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?