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

IT技术 javascript reactjs react-hooks
2021-05-19 17:08:47

我正在使用 useContext react-hooks。

时代.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

1个回答

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