Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@portabletext/react

Package Overview
Dependencies
Maintainers
9
Versions
35
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

  • 3.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
219K
increased by9.08%
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

Keywords

FAQs

Package last updated on 06 Dec 2024

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