@tinacms/preview-helpers
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-20230419194855 • Public • Published
import client from '../../tina/__generated__/client'
import { useTina } from 'tinacms/dist/react'
import { editField, useEditEvent, expandQueryWithMetadata } from '@tinacms/preview-helpers'

const MyBlogComponent = props => {
  return (<div>
    <h1>{props.title}</h1>
    <img  data-vercel-edit-info={editField(props, 'image')} src={props.image} />
  </div>)
}

export const Page = props => {
  const { data } = useTina(props)
  useEditEvent("/admin")

  return <MyBlogComponent {...data} />
}

export const getStaticProps = async ({ params }) => {
  const variables = { relativePath: `${params.filename}.md` }
  let props = await client.queries.documentation(variables)

  if (process.env.VERCEL_ENV === 'preview') {
    props = await expandQueryWithMetadata(props, client)
  }
  return {
    props: { ...props, variables },
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @tinacms/preview-helpers

Weekly Downloads

1

Version

0.0.0-20230419194855

License

Apache-2.0

Unpacked Size

43.7 kB

Total Files

9

Last publish

Collaborators

  • warwick_tinacms
  • kldavis4
  • scottgallant
  • jeffsee55