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:
- First to get the record with the mentioned docID:
- Then we add another function to edit that record where we have to merge the input (userID) into the likes array:
When that is done, back to React Studio, we configure the action for the user to like the document as in the screenshot:
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.