反应钩子“useContext"在函数“age"中调用它既不是 React 函数组件,也不是自定义的 React Hook 函数 [英] React Hook "useContext" is called in function "age" which is neither a React function component or a custom React Hook function

查看:45
本文介绍了反应钩子“useContext"在函数“age"中调用它既不是 React 函数组件,也不是自定义的 React Hook 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 useContext 反应钩子.

I am using useContext react hook.

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" 是在函数 "age" 中调用的,它既不是 React 函数组件,也不是自定义的 React Hook 函数

推荐答案

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

Function components should start with uppercase , rename age to Age, to get rid of the error

这篇关于反应钩子“useContext"在函数“age"中调用它既不是 React 函数组件,也不是自定义的 React Hook 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆