Socket
Socket
Sign inDemoInstall

@portabletext/react

Package Overview
Dependencies
Maintainers
8
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@portabletext/react

Render Portable Text with React


Version published
Weekly downloads
194K
increased by4.59%
Maintainers
8
Weekly downloads
 
Created

What is @portabletext/react?

@portabletext/react is a React component for rendering Portable Text, a JSON-based rich text format. It allows developers to easily integrate and render rich text content in their React applications, providing flexibility and customization options.

What are @portabletext/react's main functionalities?

Basic Rendering

This feature allows you to render basic Portable Text content. The example shows how to render a simple 'Hello, world!' text.

import { PortableText } from '@portabletext/react';

const content = [
  {
    _type: 'block',
    children: [
      { _type: 'span', text: 'Hello, world!' }
    ]
  }
];

function App() {
  return <PortableText value={content} />;
}

Custom Components

This feature allows you to define custom components for different types of Portable Text content. The example shows how to render a block as an h1 element.

import { PortableText } from '@portabletext/react';

const content = [
  {
    _type: 'block',
    children: [
      { _type: 'span', text: 'Hello, world!' }
    ]
  }
];

const customComponents = {
  types: {
    block: ({ children }) => <h1>{children}</h1>
  }
};

function App() {
  return <PortableText value={content} components={customComponents} />;
}

Custom Marks

This feature allows you to define custom components for text marks. The example shows how to render text with a 'strong' mark as a bold element.

import { PortableText } from '@portabletext/react';

const content = [
  {
    _type: 'block',
    children: [
      { _type: 'span', text: 'Hello, world!', marks: ['strong'] }
    ]
  }
];

const customComponents = {
  marks: {
    strong: ({ children }) => <strong>{children}</strong>
  }
};

function App() {
  return <PortableText value={content} components={customComponents} />;
}

Other packages similar to @portabletext/react

Keywords

FAQs

Package last updated on 23 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc