Remove a value from an Array in Xano

I keep digging in React Studio + Xano and I am stuck in this. I am replicating the process of likes that I had in Firestore. Basically I have an array field in each document. When the user likes some document, he introduces the userID into that array. If the user dislike a document, the userID is removed from the array. I had the behaviour working just fine with Firestore.

Now with Xano I have achieved to do the first part. Adding the userID into the likes array. I am going to explain it here just in case it is useful. First in Xano we go to the API section and create a POST API where the expected Inputs will be the docID and the likes array. Then in the function stack we need two things:

That is working just fine for me but I receive an error message in the console even though the userID is added to the array:

I would like to know how to solve that error. In the other hand, I am trying to do the opposite process: to remove the userID from the array but I am not able to achieve it. This is what I have done.

  • In Xano, I have created an API with the same inputs: docID and the input for the likes array.
  • Then in the function stack, first we get the record as before. Then I use the “Find all elements” in the array as suggested in Xano documentation:

    Then back to React Studio, I configure the dislike pretty similar to what I did before:

    It is obvious that I am doing something wrong because it does not work. I have tried to use the “delete” method but I believe that is meant to actually delete a document, not to update an array as I am trying.

I have also tried to change the backend process using the forEach function but it didn’t work as well. If someone sees the error and can point me in the right direction I would appreciate it.

Thanks!

Hi,

First I’d check that the API works in Xano. You can simply test it out where you create the endpoint. You’ll find more info regarding this from Xano’s forum: https://community.xano.com/home

If the API works in Xano then check that the API call is well formatted (e.g. data slots are actually added “as values” into the body of the POST). You can check the API call from browser’s Developer tools under “Network” tab (I’m not 100% sure if this was the right place)…

1 Like

Ok! I am going to check everything again. I understand that it is just fine in the React Studio side as I did it. It must be something related with the functions in Xano. Thank you.

1 Like