New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@portabletext/react

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@portabletext/react

Render Portable Text with React

3.2.1
latest
Version published
Weekly downloads
238K
-1.96%
Maintainers
9
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

FAQs

Package last updated on 06 Feb 2025

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