TypeError:销毁不是函数NextJS
当我将NextJS应用程序从9升级到12时。显示了一些错误,这些错误在以前的版本中没有得到照顾。其中之一是:typeError:destion destion不是函数
在控制台中,我可以看到它提到的next-dev.js?3515:25警告:使用效应不得返回函数以外的任何内容,用于清理。您返回了null。如果您的效果不需要清理,请返回未定义(或者没有任何
不确定是因为NextJ的更新在检查过程中变得过于严格,但是我会为自己和每个人都放下解决方案。
When I upgraded nextjs application from 9 to 12. There were some errors shown, that were not being taken take care of in previous version. One of them was: typeError: destroy is not a function
In the console I could see it mentioned next-dev.js?3515:25 Warning: useEffect must not return anything besides a function, which is used for clean-up. You returned null. If your effect does not require clean up, return undefined (or nothing
Not sure it was because of the update nextjs has become too strict during it's checking, but I will put it down the solution for myself and everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在几乎所有情况下,当您尝试从使用效果挂钩中返回任何功能的任何内容时,都会发生此错误。
错误
或
修复程序
有关更多信息,请阅读以下文章,
https://typeofnan.dev/fix-uncaught-typeerror-destroy-is-is-not-a-not-a-function-in-react/
In almost all of the cases this error occurs when you tried to return anything from your useEffect hook that is not a function.
The fault,
or
The Fix,
For more information read the following article,
https://typeofnan.dev/fix-uncaught-typeerror-destroy-is-not-a-function-in-react/
我也遇到了同样的问题,我的下一个应用程序从V9升级到V12。我之所以找到它,是因为
以前的使用效果像(我的下一个v9)=
这是我的下一个V12(我删除返回代码)=
我不知道为什么,我只是在使用效果中删除我的所有返回代码,这对我来说是工作的
更新:
更新,我发现,如果您使用使用效果和异步,请等待。不要喜欢它
但是您可以在使用效果之外创建函数异步等待,例如
I also got the same issue, i was upgraded my Next App from v9 to v12. And i found it because the useEffect
My code before was like (my Next v9) =
and this is my Next v12 (I remove the return code) =
I don't know why, I just remove all my return code in my useEffect and it's work for me
Update:
Update, i found that if you are using useEffect and async await. Don't use like it
but you can create function async await outside the useEffect, for example
我要维护的代码中有很多位置,例如使用
null
喜欢:There were a lot of place in the code which I am maintining where useEffect was returning
null
like:从React 17更新为18时,我会遇到相同的错误,但是就我而言,这是由
usefect
在异步中引起的。删除异步/等待,然后切换到。
代码失败的代码
有效的
I got this same error when updating from react 17 to 18, but in my case it was caused by the function in a
useEffect
being async. Removing async/await and switching to.then(result => {...}
fixed it for me.Eks:
Code that failed
Code that works
这是因为异步回调不能用于使用效率。让我们了解无法直接从useFeff()挂钩直接调用异步回调函数的原因。这是因为使用效果挂钩期望其效应功能返回清理功能或根本没有
It is because async callbacks cannot be used in useEffect. Let's understand the reasons why an asynchronous callback function cannot be called directly from a useEffect() hook. This is because the useEffect hook expects its effect function to return either a cleanup function or nothing at all
对我来说,错误是我制作了
useffect
函数差异异步For me, the error was that I made the
useEffect
function asynchronous