一个类似的问题,然而,我似乎无法代码我的方式摆脱它。
链接到类似问题的Possible EventEmitter memory leak detected without EventEmiter
请在下面找到代码:
我怀疑CreateThread组件的“input”中的错误处理导致了这些问题,但在这一点上,我真的不确定任何事情了。尽管如此,头中的连接按钮可能是罪魁祸首,因为控制台提示“accountChanged侦听器”,但是我不记得添加了什么不寻常的内容。(为清晰度添加图像)

有谁能在这个问题上大放异彩呢?我已经非常感激了!
CreateThread.js组件
import { abi, contractAddresses } from "../constants";
import { useMoralis } from "react-moralis";
import { useEffect, useState } from "react";
export default function startThread() {
const { chainId: chainIdHex, isWeb3Enabled } = useMoralis();
const chainId = parseInt(chainIdHex);
const threadAddress =
chainIdHex in contractAddresses ? contractAddresses[chainId][0] : null;
const [threadtitle, setthreadtitle] = useState("");
const [threadpost, setthreadpost] = useState("");
const { runContractFunction: createThread } = useWeb3Contract({
abi: abi,
contractAddress: threadAddress,
functionName: "createThread",
params: { _threadTitle: threadtitle, _threadPost: threadpost }, //these parameters should come from the input boxes (document.getElementById("threadtitle").value, etc.)
msgValue: {},
});
async function Update() {
const response = await createThread();
console.log(response);
}
useEffect(() => {
if (isWeb3Enabled) {
}
}, []);
return (
<div>
<div className="bg-slate-400 w-screen h-96 py-4 px-2">
<div>Threadtitle</div>
<input
className=" w-11/12"
id="threadtitle"
onChange={(e) => setthreadtitle(e.target.value)}
></input>
<div>Threadpost</div>
<input
className=" w-11/12 h-24"
id="threadpost"
onChange={(e) => setthreadpost(e.target.value)}
></input>
<div className="py-4">
<button
className="bg-blue-500 hover:bg-blue-400 text-white font-bold py-2 px-4 border-b-4 border-blue-700 hover:border-blue-500 rounded"
onClick={Update}
>
Create Thread
</button>
</div>
</div>
</div>
);
}Header.js
import { ConnectButton } from "web3uikit";
export default function Header() {
return (
<div className="p-5 border-b-2 flex flex-row bg-slate-400">
<h1 className="py-4 px-4 font-blog text-3xl">
deAgora - Forum for the people, by the people
</h1>
<div className="ml-auto py-2 px-4">
<ConnectButton moralisAuth={false}></ConnectButton>
</div>
</div>
);
}发布于 2022-10-14 09:04:59
这个问题似乎已经通过没有不断地重新命名组件(包括web3uikit连接按钮)而得到解决(在上面的例子中,这个按钮就是头)。我感觉到,每次呈现连接按钮时,连接按钮都会添加一个侦听器,而不会在重发器上删除该侦听器(对此有更多了解的人应该确认)。
我已经将头移出路由方案,以始终显示,因此它不会在前端执行的每一项操作(如浏览导航栏)上重新显示。这似乎解决了这个问题。
https://stackoverflow.com/questions/73391383
复制相似问题