我正在使用 Nextjs + Reactjs + Typescript。如果没有 Typescript,它可以完美工作,但在使用 Typescript 时出现此错误。
顺便说一下,我useMemo
在这里使用,但我尝试在函数之外初始化它。在这两种情况下,我都遇到了相同的错误。
这是我当前正在使用的代码片段
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() {
const [walletAddress, setWalletAddress] = useState(null);
const { user, authDispatch } = useAuth();
const dAppClient = useMemo(() => new DAppClient({ name: "Beacon Docs" }), []);
const web3Modal = useMemo(() => …
Run Code Online (Sandbox Code Playgroud) #define len(a) if (a == 8) 1 \
else if (a == 3) 0 \
else -1
Run Code Online (Sandbox Code Playgroud)
这段代码只是一个例子,我们如何使用嵌套的 if else。我不想使用三元运算符,因为在这种情况下我不能使用 else if 语句。