0

I'm trying to set the address of a connected wallet into useState as string so that another function can use it to run it's function.

    const router = useRouter();
    const { walletAddress } = router.query;
    const [NFTs, setNFTs] = useState<OwnedNftsResponse>()
    const [owner, setOwner] = useState<String>()
  

  useEffect(() => {
    if (router.isReady) {
      setOwner(????);
      console.log(????);
    }
  }, [router.isReady]);

 useEffect( () => {
  if (owner) {
    async function grabber() {
        const NFTs = await alchemy.nft.getNftsForOwner(owner);//Argument of type 'string | string[] | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'
      setNFTs(NFTs);
    }
    grabber();
  }  
  }, [NFTs, owner]);

Might be going about this the wrong way, so if you know a better way?

1 Answer 1

0

Here's the answer,

import { alchemy } from "const/alchemy";
import { useEffect, useState } from "react";
import { OwnedNftsResponse } from "alchemy-sdk";
import { useAddress } from "@thirdweb-dev/react";



const BagGrabber: NextPage = () => {
    const [NFTs, setNFTs] = useState<OwnedNftsResponse>()
    const owner = useAddress()



 useEffect( () => {
  if (owner) {
    async function grabber() {
        const NFTs = await alchemy.nft.getNftsForOwner(owner as unknown as string);
      setNFTs(NFTs);
    }
    console.log(NFTs);
    grabber();
  }  
  }, [owner]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.