讲swr请求写在useEffect中遇到报错
在swr issue中找到了解决方案 点我跳转
其中,react hooks中注明了hook调用只能在最外层
Only Call Hooks at the Top Level
Don’t call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the top level of your React function, before any early returns. By following this rule, you ensure that Hooks are called in the same order each time a component renders. That’s what allows React to correctly preserve the state of Hooks between multiple
useState
anduseEffect
calls. (If you’re curious, we’ll explain this in depth below.)