bananas-sanity
v0.1.8
Published
Sanity utilities for React/Next.js front-ends
Downloads
12
Readme
bananas-sanity
Installation
npm i bananas-sanity
yarn add bananas-sanity # with yarn
Getting started
Basic query
import { SanityQuery } from 'bananas-sanity';
const query = new SanityQuery({
query: `*[_type == "dog"]`,
});
const result = await query.fetch();
With parameters
const query = new SanityQuery({
query: `*[_type == "dog" && breed == $breed]`,
});
const result = await query.fetch({
params: {
breed: 'golden retriever',
},
});
Using mixins
Transform a query in a testable and predictable way.
import { sanityMixin, SanityQuery } from 'bananas-sanity';
const query = new SanityQuery({
query: sanityMixin(({ filterDrafts }) => ({
filterDrafts, // filters Sanity drafts
/* you can add custom mixins or change order of built-in mixins */
}))`*[_type == "giraffe"]`,
});
TypeScript support
type Apple = { /* ... */ }
const query = new SanityQuery<Apple, {
color: "green" | "red",
}>({
query: `*[_type == "apple" && color == $color]`,
});
{{>main-index}}
Authors
- 5 Monkeys Agency @5m
- Ludvig Aldén @ludvigalden
- Jonathan Asplund @asplunds