react-nativesanity

WARN The default export of @sanity/client has been deprecated. Use the named export `createClient` instead


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 "[]".


Solution

  • @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.

    ...
    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....