
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeTo render a table from Sanity using @portabletext/react, you'll need to use the sanity-plugin-table plugin to create tables in your Sanity Studio, then create a custom component to render them in React.
⚠️ The sanity-plugin-table only works with Studio v2, which is deprecated. You should migrate to Studio v3 when possible. The plugin has a significant limitation: table cells only support plain strings, not rich text.
# Using yarn
yarn add sanity-plugin-table@studio-v2
# Or using Sanity CLI
sanity install tableIn your schema, add the table type to your block content array:
{
name: "body",
title: "Body",
type: "array",
of: [
{
type: "block",
},
{
type: "table", // Add this
},
],
}When rendering with @portabletext/react, you need to define a custom component for the table type:
import { PortableText } from '@portabletext/react'
const components = {
types: {
table: ({ value }) => {
const { rows } = value
return (
<table>
<tbody>
{rows.map((row, rowIndex) => (
<tr key={rowIndex}>
{row.cells.map((cell, cellIndex) => (
<td key={cellIndex}>{cell}</td>
))}
</tr>
))}
</tbody>
</table>
)
}
}
}
// Use it in your component
<PortableText value={content} components={components} />Given the limitations of the table plugin, many developers prefer creating arrays of objects to represent tabular data, then handling the table rendering on the frontend. This approach gives you more flexibility and allows for complex data structures within cells.
For more details on custom serializers and rendering Portable Text, check out the Presenting Portable Text guide in the Sanity documentation.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store