Unable to store Json RPC response in react native but able to console.log it

We have Json RPC response in {},{},{}

We are unable to save the response as a variable but can see it via console.log() after doing Jsonrcp.parse(response) which we got from the below library

We are using the JsonRPC-Lite library https://www.npmjs.com/package/jsonrpc-lite.

This is our code.

axios
    .post(
      "https://ipfs.infura.io:5001/api/v0/add?wrap-with-directory=true",
      data,
      {
        headers: {
          "Content-Type": "multipart/form-data",
        },
      }
    )
    .then(function (response) {
                            this.setState({ apireturm: reponse.data });
      console.log(response.data);
    })
    .catch(function () {
      console.log("FAILURE!!");
    });

Hi @rishab_chirania - welcome to the Infura community!
Just making sure - is this issue the same as from this post?

As far as your error, can you send over the error message you’re getting when you try to save the response as a variable, as well as the response.data you’re getting when you console log it?

Thanks!

Hi The code below is printing the response.
It would be really helpful if you can help us with how to handle json rpc in react native.
I have included the console log in 2nd part of question.

  axios
    .post(
      "https://ipfs.infura.io:5001/api/v0/add?wrap-with-directory=true",
      data,
      {
        headers: {
          "Content-Type": "multipart/form-data",
        },
      }
    )
    .then(function (response) {
      //  this.state.apireturm= response

       resp = response.data;

      console.log("resp,resp!!!!!!!!!!!!!1", resp);
    })
    .catch(function (error) {
      console.log(error);
    });

‘{“Name”:“emoji_smile_anim_a.vrx”,“Hash”:“QmZM1cZshM93GbESz5K9zyRJbZBCuoUbTb9xSZrWrKWzn2”,“Size”:“114736”}\n{“Name”:"",“Hash”:“QmeNQCppx2ptV2gSnHzT39q99TMHzYhzApZHiC6P4W8Wo1”,“Size”:“114806”}\n’

Hi @rishab_chirania - I’m not super familiar with React Native, but it doesn’t look to me like you’re actually saving your response.data to a variable, which would be why it’s not saving.

I can see you’re doing a setState with the response.data, but that won’t save it as a variable - to do that, it appears you could use AsyncStorage and setItem, as shown on this section of the docs. Otherwise, you can declare it as a variable using var and you should be able to call that variable and see the hash you’re looking to find.

1 Like