
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see you're trying to run JavaScript that manipulates the DOM in Sanity Studio. The code you've shared (document.querySelectorAll('[data-ui="Grid"]')) won't work directly in Sanity's backend because Sanity Studio is a React application, and direct DOM manipulation isn't the recommended approach.
Here are your best options depending on what you're trying to achieve:
If you want to customize the Studio UI, you should create a plugin using definePlugin. This lets you add custom React components that integrate properly with Studio:
import {definePlugin} from 'sanity'
import {useEffect} from 'react'
export const myCustomPlugin = definePlugin({
name: 'my-custom-plugin',
studio: {
components: {
layout: (props) => {
// Use React hooks like useEffect here
useEffect(() => {
// Your custom logic
const grids = document.querySelectorAll('[data-ui="Grid"]')
// Do something with grids
}, [])
return props.renderDefault(props)
}
}
}
})Then add it to your sanity.config.ts:
import {myCustomPlugin} from './plugins/myCustomPlugin'
export default defineConfig({
// ... other config
plugins: [myCustomPlugin()]
})If you're trying to add functionality to specific fields in your documents, create a custom input component in your schema.
If you need a separate interface or utility within Studio, you can create a custom tool that appears in the Studio navigation.
useEffect is the React way to run code after components render (similar to when you'd query the DOM)The plugin approach with studio.components.layout override is your best bet for running custom scripts that interact with Studio's UI elements. This gives you access to the React component lifecycle where you can safely query and manipulate DOM elements using useEffect.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store