4

I'm currently learning React-Native. I try to use sanity in my project.

1

This is my sanity.js page. I could not get why sanityClient is strike-through.

I also get this error " WARN The default export of @sanity/client has been deprecated. Use the named export createClient instead". I Googled but I did not fix.

Do you have any idea?

I use Sanity to call data from Sanity. Normally when i run my program, I supposed to see some data from Sanity on my terminal but it comes as a null array "[]".

2
  • The error message has already told you what to do. If you don't understand what e.g. a named export is, that's some basic research you need to do. If you're following some specific tutorial that has got you to this point, the error is effectively telling you that the tutorial is out of date and so you should probably seek a more up to date one. Mar 16, 2023 at 7:15
  • 5
    Damien, you are not being helpful or sensible to other persons. Please learn something for yourself here. Mar 19, 2023 at 3:27

1 Answer 1

5

@Huseyin_Kara, the warning is an easy one to receive, for anyone, as it is to do with a change of interface in Sanity V3.

And it can bite especially for code that hasn't been upgraded in its package.json so that the later @sanity/client version wouldn't be present after npm install or npm upgrade. Which might well be true in a published project you may be working from, as many of those still use v2 code.

Given you are also getting an empty array back from calling the client, there could be other problems, such as not identifying the proper dataset, not having Published your edit of the Sanity data when you are targeting the production version of the dataset, or not having a matching API Access token with the right privileges yet.

I might suggest that you set useCdn to false, also, while you are working on the project, so that you get results right away after your Studio edits.

  • you could in fact ignore this warning for the present and in a learning exercise, as the default export is still present, at least at present. You'd mark perhaps with a todo flagged comment to change it later if you continue to use the code.

  • it's also likely that the updated V3 client package will work even if you are working with a V2 Sanity project. I'd see about the suggestions to see if you can get your results without this change first. But in the case you want to try this, you could change your code this way, I suspect:

...
import { createCliemt } from '@sanity/client'

const client = createClient ({
  ...
})

...

That's pretty straightforward, and is what the warning is trying to suggest you do, but it depends on having a later version of @sanity/client than you may have registered at present.

To remedy that, you could do npm install @sanity/client@latest. I think that will work even with v2 code, but because there's a question, once again I'd save this step until you've got the original client version working by following through on the suggestions.

Sanity is a quite complex tool, and a very good, capable one. It takes some time and experience with it to gain confident knowledge, and I am sure you will. Good fortune, then....

2
  • Thank you very much for your good and detailed explanation! Mar 21, 2023 at 8:03
  • Im using the tutorial here sanity.io/blog/build-your-own-blog-with-sanity-and-next-js and my client.ts also has the strike-through on sanityClient({ .. however the app works fine and the data comes through from Sanity correctly. Also while it will run on npm run dev, when i try to build it there a many typescript errors Mar 26, 2023 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.