【问题标题】:React Hook "useContext" is called in function "age" which is neither a React function component or a custom React Hook functionReact Hook "useContext" 在函数 "age" 中被调用,它既不是 React 函数组件也不是自定义 React Hook 函数
【发布时间】:2020-02-03 14:34:35
【问题描述】:

我正在使用 useContext 反应钩子。

Age.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

【问题讨论】:

    标签: javascript reactjs react-hooks


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 2019-09-14
      • 2020-11-02
      • 2022-01-12
      • 2020-07-04
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多