Programing

리액션 후크 "useContext"는 리액션 기능 구성 요소 또는 사용자 정의 리액션 후크 기능이 아닌 함수 "age"에서 호출된다.

c10106 2022. 3. 8. 21:51
반응형

리액션 후크 "useContext"는 리액션 기능 구성 요소 또는 사용자 정의 리액션 후크 기능이 아닌 함수 "age"에서 호출된다.

나는 useContext reaction 훅을 사용하고 있다.

연령.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

기능 구성요소는 대소문자를 구분하여 에러를 제거하기 위해 에이지로 변경해야 한다.

참조URL: https://stackoverflow.com/questions/60041349/react-hook-usecontext-is-called-in-function-age-which-is-neither-a-react-fun

반응형