I am trying to make a counter that counts how many NFTs are minted. I have an async function, getTotalTokensMinted, that gets the total number of tokens minted from a smart contract. How do I render the HTML so it displays the return value, numTokens, from getTotalTokensMinted? Should I use useState hook or local storage?
The code I have below returns a
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render
import React, { useEffect, useState } from 'react';
import { ethers } from 'ethers';
import './styles/App.css';
import myEpicNFT from './utils/MyEpicNFT.json';
const TOTAL_MINT_COUNT = 3;
const CONTRACTADDRESS = "0x6fe91f4814f372Eb40B547114CD75B76DF5f53dC";
const App = () => {
//const [NFTsMinted, NFTcounter] = useState(0);
const getTotalTokensMinted = async () => {
const { ethereum } = window;
let numTokens;
try {
if (ethereum) {
const provider = new ethers.providers.Web3Provider(ethereum);
const signer = provider.getSigner();
const connectedContract = new ethers.Contract(contractAddress, contractABI, signer);
numTokens = await connectedContract.getTokenNumber();
return numTokens;
}
} catch (error){
console.log(error);
}
return(
<div> {numTokens}</div>
);
}
return (
<div className="App">
<div className="container">
<p className = "sub-text">
NFT MINTED = {getTotalTokensMinted} / { TOTAL_MINT_COUNT }
</p>
</div>
</div>
</div>
);
}