react 자주겪는 문제 해결방법

hee hyeon·2021년 1월 11일
9
post-thumbnail

그냥 리액트를 하면서 겪던 린트 에러들 또는 자주 발생했던 에러에 대한 해결방법 모음집 (지속적 업데이트)

1. 'React' must be in scope when using JSX

import React from 'react'

위와 같이 임포트해주면 끝. (안해주거나 소문자로 리액트를 임포트 하면 발생하는 에러)

2. TS2322: typescript에서 useRef를 사용할 때

Type 'MutableRefObject<HTMLInputElement | undefined>' is not assignable to type 'string | ((instance: HTMLInputElement | null) => void) | RefObject<HTMLInputElement> | null | undefined'.
  Type 'MutableRefObject<HTMLInputElement | undefined>' is not assignable to type 'RefObject<HTMLInputElement>'.
    Types of property 'current' are incompatible.
      Type 'HTMLInputElement | undefined' is not assignable to type 'HTMLInputElement | null'.
        Type 'undefined' is not assignable to type 'HTMLInputElement | null'.  TS2322

useRef 선언시에 null을 빼트려서 나오는 에러임.

const abc = useRef<해당하는엘리먼트객체>(null)

해주면 끝

profile
디자인도 개발도 좋아하며 프론트엔더를 사칭하는 괴발자

2개의 댓글

comment-user-thumbnail
2022년 3월 14일

오류 잘 수정했네요 감사합니다!

답글 달기
comment-user-thumbnail
2022년 11월 24일

굿!

답글 달기