sanity

Next.js: Reduce data fetching and share data between pages

情到浓时终转凉″ 提交于 2020-08-02 01:01:06
问题 I'm looking for solutions for better data fetching in a Next.js app. In this question I'm not just looking for a solution, I'm looking for multiple options so we can look at the pros and cons. The problem I have Right now I have a few pages that all include a component that displays som static content and a that have some dynamic content that is fetched from an API. Each page do a fetch() in their getInitialProps() to get their own page data, but also the footer data, which is the same for

Next.js: Reduce data fetching and share data between pages

大憨熊 提交于 2020-08-02 01:00:10
问题 I'm looking for solutions for better data fetching in a Next.js app. In this question I'm not just looking for a solution, I'm looking for multiple options so we can look at the pros and cons. The problem I have Right now I have a few pages that all include a component that displays som static content and a that have some dynamic content that is fetched from an API. Each page do a fetch() in their getInitialProps() to get their own page data, but also the footer data, which is the same for

Fetch _id of last created document of given type in Sanity

徘徊边缘 提交于 2019-12-24 07:13:35
问题 In Sanity, for a given document type named message , how can I get the _id of the newest message document? 回答1: Query You can actually do that in a single query in GROQ (Sanity's query language): *[_type == 'message'] | order(_createdAt desc) [0] ._id Query Explanation This query has five parts. *[_type == 'message'] : select all documents of type 'message' . | : pipe the messages (so we can perform the rest of the operations) order(_createdAt desc) : order the messages from newest to oldest