Tinacms Developer Docs

Visual Editing

Enable real-time visual editing so content changes appear instantly as editors type

Visual editing is TinaCMS's signature feature. It allows editors to see their content changes in real-time on a live preview of the site, side-by-side with the editing form.

How It Works

When visual editing is enabled:

  1. Your site renders alongside the TinaCMS editor
  2. As editors type, the page updates instantly
  3. Changes are not saved until the editor clicks "Save"

Requirements

Visual Editing Requirements

Before setting up visual editing, your page must:

  • Use TinaCMS data fetching (not direct file reads)
  • Support client-side rendering
  • Be built with React or a React-based framework

The useTina Hook

Visual editing is powered by the useTina hook. This hook:

  • Re-hydrates your page data as the editor types
  • Registers fields for the editing sidebar
  • In production, simply passes through the initial data
import { useTina } from 'tinacms/dist/react'

function Page(props) {
  const { data } = useTina({
    query: props.query,
    variables: props.variables,
    data: props.data,
  })

  // Use `data` (not `props.data`) to get live updates
  return <h1>{data.page.title}</h1>
}

Setup Overview

1. Fetch Data with TinaCMS

Use the generated client to fetch your content:

const response = await client.queries.page({
  relativePath: 'home.mdx',
})

2. Pass Data to Your Component

Include the query, variables, and data in your props:

return {
  props: {
    query: response.query,
    variables: response.variables,
    data: response.data,
  },
}

3. Use the useTina Hook

In your component, wrap the data with useTina:

const { data } = useTina({
  query: props.query,
  variables: props.variables,
  data: props.data,
})

4. Render Using the Hook's Data

Always use the data returned from useTina:

return <h1>{data.page.title}</h1>

Framework Examples

Next.js Pages Router

// pages/[slug].tsx
import { useTina } from 'tinacms/dist/react'
import { client } from '../tina/__generated__/client'

export default function Page(props) {
  const { data } = useTina({
    query: props.query,
    variables: props.variables,
    data: props.data,
  })

  return (
    <main>
      <h1>{data.page.title}</h1>
    </main>
  )
}

export async function getStaticProps({ params }) {
  const response = await client.queries.page({
    relativePath: `${params.slug}.mdx`,
  })

  return {
    props: {
      query: response.query,
      variables: response.variables,
      data: response.data,
    },
  }
}

Next.js App Router

// app/[slug]/page.tsx (Client Component)
'use client'

import { useTina } from 'tinacms/dist/react'

export default function PageClient({ query, variables, data }) {
  const { data: tinaData } = useTina({ query, variables, data })

  return (
    <main>
      <h1>{tinaData.page.title}</h1>
    </main>
  )
}
// app/[slug]/page.server.tsx (Server Component wrapper)
import { client } from '@/tina/__generated__/client'
import PageClient from './page'

export default async function Page({ params }) {
  const response = await client.queries.page({
    relativePath: `${params.slug}.mdx`,
  })

  return (
    <PageClient
      query={response.query}
      variables={response.variables}
      data={response.data}
    />
  )
}

Router Configuration

To enable clicking from the editor directly to pages, configure the router property on your collection:

// tina/config.ts
{
  name: 'page',
  path: 'content/pages',
  ui: {
    router: ({ document }) => {
      if (document._sys.filename === 'home') {
        return '/'
      }
      return `/${document._sys.filename}`
    },
  },
  fields: [...],
}

Production Behavior

In production (when not in edit mode):

  • useTina simply returns the initial data unchanged
  • No additional JavaScript is loaded for editing
  • Zero performance impact on your production site

Limitations

  • Only works with React-based frameworks
  • Requires client-side rendering capability
  • Each useTina hook corresponds to one form in the sidebar

Multiple Forms

If you have multiple useTina hooks on a page (e.g., page content + global config), the first one determines which form shows in the sidebar by default.

On this page