How to use the react-tinacms.useCMS function in react-tinacms

To help you get started, we’ve selected a few react-tinacms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tinacms / tinacms / packages / next-tinacms-markdown / src / index.ts View on Github external
export function useMarkdownForm(
  markdownRemark: Markdown,
  formOverrrides: FormOptions
) {
  const cms = useCMS()

  // let throttledOnChange = React.useMemo(() => {
  // return throttle(cms.api.git.onChange, 300)
  // }, [])
  const [values, form] = useLocalForm({
    label: markdownRemark.path,
    id: markdownRemark.path,
    initialValues: markdownRemark,
    async onSubmit(data) {
      console.log({ data })
      await cms.api.git.onChange!({
        fileRelativePath: data.path,
        content: toMarkdownString(data),
      })
      return await cms.api.git.onSubmit!({
        files: [data.path],
github tinacms / tinacms / packages / gatsby-tinacms-json / src / use-json-form.ts View on Github external
jsonNode: JsonNode | null,
  formOptions: Partial> = {}
): [JsonNode | null, Form | null] {
  /**
   * We're returning early here which means all the hooks called by this hook
   * violate the rules of hooks. In the case of the check for
   * `NODE_ENV === 'production'` this should be a non-issue because NODE_ENV
   * will never change at runtime.
   */
  if (!jsonNode || process.env.NODE_ENV === 'production') {
    return [jsonNode, null]
  }
  validateJsonNode(jsonNode)

  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  const cms = useCMS()
  const label = formOptions.label || jsonNode.fileRelativePath
  const id = jsonNode.fileRelativePath

  /**
   * The state of the JsonForm, generated from the contents of the
   * Json file currently on disk. This state will contain any
   * un-committed changes in the Json file.
   */
  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  const valuesOnDisk = useMemo(
    () => ({
      jsonNode: jsonNode,
      rawJson: JSON.parse(jsonNode.rawJson),
    }),
    [jsonNode]
  )
github tinacms / tinacms / packages / gatsby-tinacms-remark / src / useRemarkForm.tsx View on Github external
formOverrrides: Partial> = {}
) {
  /**
   * We're returning early here which means all the hooks called by this hook
   * violate the rules of hooks. In the case of the check for
   * `NODE_ENV === 'production'` this should be a non-issue because NODE_ENV
   * will never change at runtime.
   */
  if (!markdownRemark || process.env.NODE_ENV === 'production') {
    return [markdownRemark, null]
  }

  validateMarkdownRemark(markdownRemark)

  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  const cms = useCMS()
  const label = formOverrrides.label || markdownRemark.frontmatter.title
  const id = markdownRemark.fileRelativePath

  /**
   * The state of the RemarkForm, generated from the contents of the
   * Markdown file currently on disk. This state will contain any
   * un-committed changes in the Markdown file.
   */
  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  const valuesOnDisk = useMemo(
    () => ({
      fileRelativePath: markdownRemark.fileRelativePath,
      frontmatter: markdownRemark.frontmatter,
      rawMarkdownBody: markdownRemark.rawMarkdownBody,
      rawFrontmatter: JSON.parse(markdownRemark.rawFrontmatter),
    }),
github tinacms / tinacms / packages / tinacms / src / plugins / fields / ImageFieldPlugin.tsx View on Github external
export const ImageField = wrapFieldsWithMeta(props => {
  const cms = useCMS()

  return (
     {
        acceptedFiles.forEach(async (file: any) => {
          // @ts-ignore
          await cms.api.git!.onUploadMedia!({
            directory: props.field.uploadDir(props.form.getState().values),
            content: file,
          })
          props.input.onChange(file.name)
        })
      }}
    />
github tinacms / tinacms / packages / gatsby-tinacms-json / index.ts View on Github external
formOptions: Partial> = {}
) {
  /**
   * We're returning early here which means all the hooks called by this hook
   * violate the rules of hooks. In the case of the check for
   * `NODE_ENV === 'production'` this should be a non-issue because NODE_ENV
   * will never change at runtime.
   */
  if (!jsonNode || process.env.NODE_ENV === 'production') {
    return [jsonNode, null]
  }

  validateJsonNode(jsonNode)

  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  const cms = useCMS()
  const label = jsonNode.fileRelativePath
  const id = jsonNode.fileRelativePath

  /**
   * The state of the JsonForm, generated from the contents of the
   * Json file currently on disk. This state will contain any
   * un-committed changes in the Json file.
   */
  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  const valuesOnDisk = useMemo(
    () => ({
      jsonNode: jsonNode,
      rawJson: JSON.parse(jsonNode.rawJson),
    }),
    [jsonNode]
  )
github tinacms / tinacms / packages / gatsby-tinacms-json / index.ts View on Github external
export function useJsonForm(
  jsonNode: JsonNode,
  formOptions: Partial> = {}
) {
  if (!jsonNode || process.env.NODE_ENV === 'production') {
    return [{}, null]
  }
  validateJsonNode(jsonNode)

  const cms = useCMS()
  const label = jsonNode.fileRelativePath
  const id = jsonNode.fileRelativePath

  /**
   * The state of the JsonForm, generated from the contents of the
   * Json file currently on disk. This state will contain any
   * un-committed changes in the Json file.
   */
  const valuesOnDisk = useMemo(
    () => ({
      jsonNode: jsonNode,
      rawJson: JSON.parse(jsonNode.rawJson),
    }),
    [jsonNode]
  )
github tinacms / tinacms / packages / demo-next / pages / [slug].js View on Github external
export default function Page(props) {

  let cms = useCMS()

  let [post, form] = useCMSForm({
    id: props.fileRelativePath,
    label: "blogpost",
    initialValues: {
      title: props.title
    },
    fields: [
      {
        name: "title",
        component: "text"
      }
    ],
  })

  let writeToDisk = React.useCallback(formState => {
github tinacms / tinacms / packages / gatsby-tinacms-remark / src / form-actions / delete-action.tsx View on Github external
export function DeleteAction({ form }: { form: Form }) {
  const cms = useCMS()
  return (
     {
        if (
          !confirm(
            `Are you sure you want to delete ${form.values.fileRelativePath}?`
          )
        ) {
          return
        }
        await cms.api.git.onDelete!({
          relPath: form.values.fileRelativePath,
        })

        window.history.back()
      }}

react-tinacms

> This package is no longer necessary or supported. You may instaed use the [`tinacms`](https://www.npmjs.com/tinacms) package directly.

Apache-2.0
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis