I have encountered an error while using Nextjs with Reactjs and Typescript. Interestingly, the code works perfectly fine without Typescript, but as soon as I introduce Typescript, I run into this issue.
Specifically, I am utilizing the useMemo
hook in my implementation. I attempted moving its initialization outside of the function, yet the error persists regardless of the approach.
Included below is a snippet of the code that I am currently employing:
const INFURA_ID = process.env.REACT_APP_INFURA_ID;
const initWeb3 = (provider: any) => {
const web3 = new Web3(provider);
web3.eth.extend({
methods: [
{
name: "chainId",
call: "eth_chainId",
outputFormatter: web3.utils.hexToNumber as any,
},
],
});
return web3;
};
export function Web3UtilityProvider() {
// ...remaining code