---
title: "New `defineModule` Helper and Richer Module Previews"
description: "Two QoL improvements to SanityPress: a defineModule helper eliminating module schema boilerplate, and richer module previews to surface UID and hidden states."
---

![New `defineModule` Helper and Richer Module Previews](https://cdn.sanity.io/images/cyu7k2r0/production/0710a8fdd47ee43ae5aaa5db1167da8f5d77529b-1536x1024.png?blur=30&q=100&auto=format)

# QoL Improvements: New \`defineModule\` Helper and Richer Module Previews

![Mitchell Christ](https://cdn.sanity.io/images/cyu7k2r0/production/26bddd620298806d202e516a4078eab89dc8117a-1254x1254.png?q=100&auto=format)

By Mitchell Christ

* [Changelog](https://sanitypress.dev/blog?category=changelog),
* [Sanity](https://sanitypress.dev/blog?category=sanity)
Apr 24, 20262 min read

On this page
1. [defineModule()](#definemodule)
2. [Richer module previews](#richer-module-previews)
3. [Start building with SanityPress](#start-building-with-sanitypress)

### Ready to build your next website with SanityPress?

[🚀 Get started today](https://sanitypress.dev/docs/getting-started)

![Napoleon Dynamite holding two pieces of paper one with closed eyeball icon and the other with a "#". in the style of an awkward yearbook photo from the 80s](https://cdn.sanity.io/images/cyu7k2r0/production/0710a8fdd47ee43ae5aaa5db1167da8f5d77529b-1536x1024.png?q=100&auto=format)

Two small quality of life improvements have landed recently in SanityPress: a `defineModule` helper for developers writing module schemas, and richer array item previews in the Studio for editors managing page content. Neither is a major feature—they’re the kind of change that makes everyday work a bit less error-prone and a bit more informative.

On the schema side, every module had to manually wire up an `attributes` field of type `module-attributes`, an `options` group to house it, the `hidden` and `uid` values in `preview.select` and `prepare()`, and a `components.preview` pointing at the shared preview component. That’s roughly 15 lines that had to be exactly right in every module. Easy to omit, and not loud when wrong.

## `defineModule()`

`defineModule` is a wrapper around Sanity’s `defineType()` that handles all of that automatically. Pass it your fields and any custom groups as usual, and it takes care of the rest:

* src/sanity/schemaTypes/modules/my-module.ts

```
import defineModule from '@/sanity/schemaTypes/fragments/define-module'

export default defineModule({
  name: 'hero-banner',
  title: 'Hero banner',
  type: 'object',
  icon: SomeIcon,
  groups: [{ name: 'content', default: true }],
  fields: [
    // your fields here
  ],
  // ...
})
```

The `options` group is appended automatically. The `attributes` field is prepended and assigned to it. The `preview.select` is extended to include `attributes`, and `prepare()` is wrapped to pull `hidden` and `uid` out. The `components.preview` is set to the shared `modulePreview` component.

All existing SanityPress module schemas now use this new `defineModule` helper function. The [/new-module skill](https://sanitypress.dev/blog/new-module-skill-claude-code) has also been updated to scaffold new modules with it by default, so the pattern is enforced going forward without any extra thought.

## Richer module previews

The `modulePreview` component that `defineModule` sets on every module got two new additions: a UID badge and a hidden indicator.

![New badges for UID values and hidden modules](https://cdn.sanity.io/images/cyu7k2r0/production/349bd69b41b24ee106e29e9f2c5fbdc999e98f17-1384x772.png?q=100&auto=format)

New badges for UID values and hidden modules

When a module has a `uid` set, a small `#uid` badge appears right-aligned in the array item row. When a module is marked hidden, an eye-closed icon shows in its place. Both pull from `module-attributes`, the same `uid` that becomes the HTML `id` attribute for anchor links, and the same `hidden` flag that suppresses the module on the frontend.

The implementation uses Sanity’s custom preview component API: extend `PreviewProps` with your extra props, call `renderDefault(props)` to keep the schema’s own preview intact, and layer in your additions.

> Sanity’s guide on [creating richer array item previews](https://www.sanity.io/docs/developer-guides/create-richer-array-item-previews) covers the full pattern in detail.

## Start building with SanityPress

`defineModule` and the updated module previews ship with SanityPress—a production-ready starter built on Sanity, Next.js, and Tailwind. If you’re building on it, every new module you scaffold gets the right structure and the right Studio experience out of the box.

[Get started with SanityPress today.](https://sanitypress.dev/docs/getting-started)

![Pedro wearing a black t-shirt with the text "Vote for SanityPress"](https://cdn.sanity.io/images/cyu7k2r0/production/bdab1b7177ec1a860715b7149c647f0c55add0cb-1537x1023.png?q=100&auto=format)

1. [Home](https://sanitypress.dev/)
2. [Blog](https://sanitypress.dev/blog)
3. QoL Improvements: New \`defineModule\` Helper and Richer Module Previews

## Stop Scaffolding. Start Shipping.

[🚀 Start building](https://sanitypress.dev/docs/getting-started)[⭐ Star on GitHub](https://sanitypress.dev/repo)
