[SOLVED] Error too many re-renders

I am trying to runcontractfunction to check for approvals on a user account however I keep getting the Error too many re-renders Can anyone direct me on how to mitigate this?

maybe is from that userEffect?
can you add a console.log in that useEffect to see how many times it is called?

I tried hard thanksss

I don’t understand what is the problem now

So a user has a number of nfts in their wallet but when unique nfts is run, it runs it down to two collections. I want to create an array of the [nftaddress, approval boolean] but the script I wrote above is problematic

This code returns the contract addresses with no duplicates.

 const uniqueNfts= [];
  

  const unique = nftBalance.filter(element => {
  const isDuplicate = uniqueNfts.includes(element.token_address);

  if (!isDuplicate) {
        uniqueNfts.push(element.token_address);
      }
    });

this part obvious creates the paramters for he contract function


    for(let t = 0; t < uniqueNfts?.length; t++){
      const approvalCheck =[]
      
      approvalCheck.push({
        abi: nftAbi,
        contractAddress: uniqueNfts[t],
        functionName: "isApprovedForAll",
        params: {
            owner: account,
            operator: seaport1?.contract.address,
        },
    })

and this part is supposed to create the array of the nftaddress against their approvals

const approvals =[]
   const check = await runContractFunction({
          params: approvalCheck[t],
          onSuccess: ()=>approvals.push({uniqueNfts[t],check}),
          onError: (error) => {
              console.log(error)
          },
      })

you could add some logging with console.log to see if everything works as expected

This is what I get from the following code. It seems to not check for the first approval. I approved that contract on etherscan

const isApproved = async()=>{
  const uniqueNfts= [];
  

  const unique = nftBalance.filter(element => {
  const isDuplicate = uniqueNfts.includes(element.token_address);

  if (!isDuplicate) {
        uniqueNfts.push(element.token_address);
      }
    });

    console.log(uniqueNfts)
    var approvals = []
    for(let t = 0; t < uniqueNfts?.length; t++){
      
      
      const approvalCheck = {
        abi: nftAbi,
        contractAddress: uniqueNfts[t],
        functionName: "isApprovedForAll",
        params: {
            owner: account,
            operator: seaport1?.contract.address,
        },
    }
    const adr = approvalCheck?.contractAddress
   
   const approved = await runContractFunction({
          params: approvalCheck,
          onSuccess: ()=>approvals.push({adr, approved}),
          onError: (error) => {
              console.log(error)
          },
      })
   
  }
  if(approvals.length == uniqueNfts.length){
  setApprove(approvals)
  }
}

Weird because when I console.log(approved) I get two instances of true but only one gets pushed into the approvals array

Found a solution thanks

1 Like