Integrating Sanity and Next.js - Which Library is Best?

3 replies
Last updated: Jul 14, 2021
hi all!I'm just starting to integrate Sanity with my Next.js app and am a bit confused which library I am supposed to use. I've seen examples using
@sanity/client
&
@sanity/image-url
,
next-sanity
and also all three libraries together. The last one confuses me as I get an impression that
next-sanity
should wrap the others. Am I right to think that
next-sanity
is the way to go?
Jul 14, 2021, 11:18 AM
Agreed, it's a bit confusing. I think the
next-sanity
-library is a kind of collection of useful libraries, including a client and image-url functions. We are using it for everything, and it works nicely for us: https://github.com/navikt/detsombetyrnoe/blob/main/src/lib/sanity.ts

One caveat I know of is that the client that's included has reduced functionality to reduce bundle-size . It's still fine for fetching data, but if you want to do writes to sanity from your frontend you have to use the
@sanity/client
.
That might be the reason why you've seen people using both packages in the same project.
Update:

Seems like the client bundled in
next-sanity
is now the default
@sanity/client
so it has full support for writes as well.
Jul 14, 2021, 1:00 PM
Yep
next-sanity
is your best place to start as it contains all the utilities you’ll need.
Jul 14, 2021, 1:22 PM
thanks
user Q
and
user T
, that's helpful!
Jul 14, 2021, 1:23 PM

Sanity.io – build remarkable experiences at scale

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

Categorized in