useMoralisQuery then save .first

I have a onclick function onClaim that gets the txnId and now I want to use that txnId to query from Transactions table. but I’m having error in .first()

 const onClaim = (txnId: any) => {
    const query = useMoralisQuery(
      "Transactions", 
      (query) =>
        query
          .equalTo("_id", txnId), 
        [],
      );
      const txnClaim = query.first()
      txnClaim.set("x",1337);
      txnClaim.save()

  }

I have a create method, but i never had a update function. I tried to query the first result

I also tried this kind of method:

 const onClaim = (txnId: any) => {
    const txnClaim = useMoralisQuery(
      "Transactions", 
      (query) =>
        query
          .equalTo("_id", txnId), 
        [],
      );
      
      txnClaim.set("x",1337);
      txnClaim.save()

  }

here is an example of my create function that works perfectly well:

   const TransactionsHistory = Moralis.Object.extend("Transactions");
   const txnHistory = new TransactionsHistory();
      txnHistory.set("ethAddress", user?.get("ethAddress"))   
      txnHistory.save();

You can add a sequence of query conditions like this.

(query) =>
query
      .equalTo("_id", txnId), 
      .first()
      [],
);

there is an error:

I tried

(query) =>
query
      .equalTo("_id", txnId), 
      .first()
      [],
);

For now try ignoring the type errors with :any to see if it works.

what do you mean? should I add :any or remove it?

Similar to this in your TypeScript project, yes add it to get around any type issues.

how? I mean where will I put the :any?

I think he meant to add it for the query to suppress the type error.

(query : any) => // <- here
query
      .equalTo("_id", txnId) // <- and we can remove the "," here. I missed
      .first()
      [],
);

And one more thing I noticed is useMoralisQuery can’t be used inside a normal function (onClaim). It should be used inside a react component function.
So you can use fetch function to call the query when required.

const { fetch } = useMoralisQuery({...
//...
{ autoFetch: false }, 
})

Since txnClaim is an a array of objects, you need to use txnClaim[0] to set and save data.