Collections & singletons

Collections & Singletons

Keystatic has two concepts or mechanisms to manage data: collections and singletons.

Collections

Think of a collection of anything you’d want multiple instances of.

A series of blog posts, cooking recipes or testimonials from happy customers.

To create a collection in your project, add a collections key to your Kesytatic config:

// Keystatic config
import { config, collection } from '@keystatic/core'

export default config({
	// ...
	collections: {
		testimonials: collection({
			label: 'Testimonials'
		})
	}
}) 

The config above creates a new testimonials collection.

Untitled

Wrapping the testimonials config object inside the collection() function provides TypeScript autocomplete goodness ✨

CleanShot 2023-03-01 at 13.54.04@2x.png

Singletons

When you want a “one-of-a-kind” data entry, such as a “Settings” page or maybe a very specific set of fields for the “Homepage” of a website… you’ll want to use a singleton

To create a singleton in your project, add a singleton key to your Keystatic config:

// Keystatic config
import { config, singleton } from '@keystatic/core'

export default config({
	// ...
	singletons: {
		homepage: singleton({
      label: 'Homepage'
			// ...
    })
	}
})

The config above creates a new homepage singleton.

CleanShot 2023-03-01 at 13.49.45@2x.png

Wrapping the homepage config object inside the singleton() function provides TypeScript autocomplete goodness ✨