Skip to content

Commit 3bdac53

Browse files
authored
feat: add sanity resource hook (#190)
1 parent 3d98105 commit 3bdac53

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { z } from "zod";
2+
import { cache } from "react";
3+
import { client } from "@/lib/sanity/client";
4+
import { SanityDocument, SanityReference } from "@/lib/sanity/types";
5+
6+
const Resources = z.array(
7+
SanityDocument.extend({
8+
_type: z.literal("resource"),
9+
link: z.string(),
10+
title: z.string(),
11+
resourceType: SanityReference,
12+
}),
13+
);
14+
15+
export const getResources = cache(async () => {
16+
return Resources.parse(await client.fetch("*[_type == 'resource']"));
17+
});

0 commit comments

Comments
 (0)