Discussion about building a custom table in Sanity and implementing custom functionality with buttons.
There are actually official table plugins for Sanity Studio that are better maintained than sanity-react-table. Here's what you should know:
Recommended Approach: Official Table Plugins
For Sanity Studio v3 (and v4), use one of these official/well-maintained plugins:
@sanity/table - The official Sanity table plugin:
npm install @sanity/tablesanity-plugin-another-table - Another solid option for v3:
npm install sanity-plugin-another-tableBoth of these are actively maintained and work with modern Sanity Studio versions. The official @sanity/table plugin is generally the safest bet since it's maintained by the Sanity team.
Why Not sanity-react-table?
The sanity-react-table library you found is likely outdated and may not be compatible with Sanity Studio v3/v4. The Sanity ecosystem has evolved significantly, and older community plugins may not work with the current architecture.
Installation & Usage
After installing, add the plugin to your sanity.config.ts:
import {defineConfig} from 'sanity'
import {table} from '@sanity/table'
export default defineConfig({
// ... other config
plugins: [
table(),
// ... other plugins
],
})Then use it in your schema:
import {defineType} from 'sanity'
export default defineType({
name: 'myDocument',
type: 'document',
fields: [
{
name: 'myTable',
type: 'table', // The type added by the plugin
},
],
})Alternative: Structured Approach
That said, the official documentation suggests that approaching your schemas in a more structured manner (using arrays of objects instead of tables) can often pay dividends down the line. Tables can sometimes be an anti-pattern in structured content - consider whether your data might be better represented as an array of objects, which gives you more flexibility for querying and rendering on the frontend.
Custom Input Components (Advanced)
If the existing table plugins don't meet your needs, you can build a custom input component. For Sanity v3+, you'll import PatchEvent, set, and unset directly from the 'sanity' package rather than the old v2 locations. However, I'd recommend starting with one of the official plugins first before going the custom route.
If you need help implementing either approach or have specific table requirements, feel free to share more about your use case!
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.