React Hook "useContext" 在函数 "age" 中调用,它既不是 React 函数组件也不是自定义 React Hook 函数



我正在使用useContext react hook。

年龄.js

import React, { useContext } from 'react' ;
import Detail from '../context/detail';
const age = props =>{
const detail = useContext(Detail);
return(
<p>
Your age is : {detail.age}
</p>
);
}
export default age ;

它给出了这样的错误React Hook "useContext" is called in function "age" which is neither a React function component or a custom React Hook function

函数组件应以大写开头,将 age 重命名为 Age,以消除错误

最新更新