Sanity Pioneers: Get early access to betas, extra AI credits, and a direct line to the engineering team. Apply now

How to show a snackbar after a document action in Sanity?

10 repliesLast updated: Nov 29, 2025

Hi! Can someone help me showing a snackbar after a document action? I am trying everything and can't make it work
AI Update

I can help you with that! To show a toast/snackbar after a document action in Sanity Studio, you need to use the useToast hook from @sanity/ui.

Here's how to implement it in a custom document action:

import {useToast} from '@sanity/ui'

export function MyCustomAction(props) {
  const toast = useToast()

  return {
    label: 'My Action',
    onHandle: () => {
      // Your action logic here
      // ...
      
      // Show success toast
      toast.push({
        status: 'success',
        title: 'Success!',
        description: 'Your action completed successfully'
      })
      
      // Close the action dialog
      props.onComplete()
    }
  }
}

Important things to note:

Here's a more complete example with error handling:

import {useToast} from '@sanity/ui'

export function MyCustomAction(props) {
  const toast = useToast()

  return {
    label: 'My Action',
    onHandle: async () => {
      try {
        // Your async action logic
        await someAsyncOperation()
        
        toast.push({
          status: 'success',
          title: 'Done!',
          description: 'Document updated successfully',
          duration: 3000 // milliseconds
        })
      } catch (error) {
        toast.push({
          status: 'error',
          title: 'Error',
          description: error.message
        })
      } finally {
        props.onComplete()
      }
    }
  }
}

You can see a real-world example in this custom document actions guide where they use useToast to show feedback after publishing Cloudinary assets.

If you're still having trouble, make sure your Studio is using a recent version of @sanity/ui (v1.0+) and that your document action is properly registered in your sanity.config.ts file. Let me know if you need help with the configuration part!

Show original thread
10 replies

Was this answer helpful?

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.

Related contributions