Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Hook "useContext" is called in function "age" which is neither a React function component or a custom React Hook function

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 ;

It gives an error like this : React Hook "useContext" is called in function "age" which is neither a React function component or a custom React Hook function

like image 597
SBofficial Avatar asked Feb 03 '20 14:02

SBofficial


1 Answers

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

like image 167
Chithambara Kumar Avatar answered Nov 02 '22 03:11

Chithambara Kumar