为了解决错误"React Hook 'useEffect' is called in function that is neither a React function component nor a custom React Hook function",可以将函数名的第一个字母大写,或者使用use
作为函数名的前缀。比如说,useCounter
使其成为一个组件或一个自定义钩子。
这里有个示例用来展示错误是如何发生的。
// App.js import React, {useEffect, useState} from 'react'; //相关文章
- 解决React报错Expected an assignment or function ca
- 解决React报错JSX element type does not have
- 解决React报错Unexpected default export of anonymou
- 解决React报错Expected `onClick` listener to be
- 解决React报错Encountered two children with the
- 解决React报错Functions are not valid as a React ch
- React中的Hooks路由跳转问题
- 解决React报错Cannot assign to 'current' because it
- 解决React报错The tag is unrecognized in this
- 解决React报错Style prop value must be an object
- Redis并发访问问题详细讲解