Fetching content
Basic usage
To fetch content you can use getContent method.
import { sdk } from '~/sdk.config';
const content = await sdk.sanity.getContent({
url: 'test'
});
In the example above we are fetching content by url
field, but there are other options as well. Check the GetContentParams interface to see all available options.
Get content by locale
You can also fetch content including the locale.
import { sdk } from '~/sdk.config';
const content = await sdk.sanity.getContent({
url: 'test',
locale: 'en_us'
});
Custom content type search
You can search content on top of custom config as well. To do this instead of using page url
or entry id
use custom
config in the search method. Like this.
const content = await sdk.sanity.getContent({
custom: {
type: 'field_type';
field: 'field_name';
value: 'field_value';
}
});
Custom queries
You can also use custom queries to fetch content. To learn more about custom queries check Sanity documentation.
import { sdk } from '~/sdk.config';
const content = await sdk.sanity.getContent({
customQuery: `*[_type == "page" && url == "test"]`
});