Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

Question about desk structure and refreshing when new documents are created.

4 replies
Last updated: Aug 24, 2023
Hey all! I've got a question about desk structure. I'm trying to create a list of documents without the top-level "add new document" and "menu" items (working around i18n not working for
for one-off content types). I've got it working querying for the content type I want and building, but it doesn't refresh when a new document that matches that criteria is created. Here's a snippet of the code:
const microcopy = await context
    .getClient({ apiVersion: '2023-08-24' })
    .fetch('*[_type == "microcopy"]');
Later, in the desk builder:

S.list().items(microcopy.map((item) =>
Aug 24, 2023, 4:06 PM
Sounds like you will need to add some sort of listener for events when new documents are added. Perhaps take a look at the useDocumentStore hook?
Returns an observable that can be used to listen for changes and events to documents in the current project.
Aug 24, 2023, 4:56 PM
Thanks, unfortunately because this is my desk structure it doesn't appear to be a React component I can use hooks with?
Aug 24, 2023, 5:57 PM
The context has documentStore, but I can't use the
to get the value of the observable
Aug 24, 2023, 6:01 PM
Ok! I got it working! Your tip on
is what sealed it. Turns out there's a sample of this working inside a studio test
Aug 24, 2023, 6:11 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?