inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Next + React Query로 SNS 서비스 만들기

보너스: 배포 맛보기(과금주의)

강좌 보면서 개인프로젝트에 적용중입니다. build시 "Arrow" cannot be used as a JSX component 에러가 납니다.

해결된 질문

390

tittogam

작성한 질문수 1

0

 

 

./src/_components/Carousel.tsx
110:6  Warning: React Hook useEffect has a missing dependency: 'nextFn'. Either include it or remove the dependency array.  react-hooks/exhaustive-deps

(....lint warning문구 생략)

info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules

   Linting and checking validity of types  .Failed to compile.


./src/_components/Carousel.tsx:137:12

Type error: 'Arrow' cannot be used as a JSX component.

  Its type 'FC<PropsWithChildren<ArrowProps>>' is not a valid JSX element type.

    Type 'FunctionComponent<PropsWithChildren<ArrowProps>>' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.

      Type 'ReactElement<any, any> | null' is not assignable to type 'ReactNode'.

        Type 'ReactElement<any, any>' is not assignable to type 'ReactNode'.

          Property 'children' is missing in type 'ReactElement<any, any>' but required in type 'ReactPortal'.

  135 |         className={`h-full w-full ${inArrow ? 'absolute' : ''} max-w-full`}>

  136 |         {!!showNavButton && (

> 137 |           <Arrow

      |            ^

  138 |             direction="left"

  139 |             executeFn={prevFn}

  140 |             inArrow={inArrow}

error Command failed with exit code 1.

 

 

'use client';
import { FC, PropsWithChildren, useEffect, useState } from 'react';

interface ArrowProps {
  direction: 'left' | 'right';
  executeFn: () => void;
  inArrow?: boolean;
  hoverStyle?: string;
}

const Arrow: FC<PropsWithChildren<ArrowProps>> = ({
  direction,
  executeFn,
  inArrow,
  hoverStyle,
  children,
  ...props
}) => {
  const [hoverColor, setHoverColor] = useState(hoverStyle || undefined);

  useEffect(() => {
    hoverStyle && setHoverColor(`hover:${hoverStyle}`);
  }, [hoverStyle]);

  const returnString = direction === 'left' ? '<' : '>';

  return (
    <div
      onClick={executeFn}
      className={`${inArrow ? 'absolute z-50' : ''} ${direction === 'left' ? 'left-0 top-0 rounded-l-lg' : 'right-0 top-0 rounded-r-lg'}  center-vertical flex h-full w-[30px] cursor-pointer text-[30px] ${hoverColor && hoverColor}`}
      {...props}>
      {returnString}
      {children}
    </div>
  );
};

export default Arrow;

 

 

next build를 했을때 해당 에러가 Arrow컴포넌트에서 발생하였습니다.

 

 

Arrow컴포넌트에서 제가 정의한 FC<PropsWithChildren<ArrowProps>>타입이 유효한 JSX element type이 아니라는 메시지 인거 같습니다.

 

이 에러가 나는 이유가

유효한 JSX엘리먼트가 아니어서 일것같아서

return 하는 jsx문법에 오류가 있는지 확인하려

div 겉에도 fragment로 감싼다거나

returnString을 해주는 중괄호 부분도 fragment로 감싸거나

children도 감싸보았습니다.

그러나 똑같은 에러가 발생하고 있는 상황입니다.

 

  const returnString = direction === 'left' ? '<' : '>';

 

혹시 위의 코드가 문제가 발생할까 싶어서 SVG파일을 만들어

조건에따라 왼쪽 오른쪽 SVG 파일 컴포넌트를 return 문 안에서 렌더링 해주었는데

여기서도 동일한 에러가 발생하였습니다.

 

Type error: 'LeftSvg' cannot be used as a JSX component.
  Its type '({ className, width, height, onClick, cyAttribute, }: { className?: string | undefined; width?: number | undefined; height?: number | undefined; onClick?: (() => void) | undefined; cyAttribute?: string | undefined; }) => JSX.Element' is not a valid JSX element type.
    Type '({ className, width, height, onClick, cyAttribute, }: { className?: string | undefined; width?: number | undefined; height?: number | undefined; onClick?: (() => void) | undefined; cyAttribute?: string | undefined; }) => JSX.Element' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.
      Type 'Element' is not assignable to type 'ReactNode'.
        Property 'children' is missing in type 'Element' but required in type 'ReactPortal'.

  24 |   }, [hoverStyle]);
  25 |
> 26 |   const returnString = direction === 'left' ? <LeftSvg /> : <RightSvg />;
     |                                                ^
  27 |
  28 |   return (
  29 |     <div
error Command failed with exit code 1.

 

 

 

참고로

'DatePicker' cannot be used as a JSX component. Its instance type 'ReactDatePicker<undefined, undefined>' is not a valid JSX element.

이런 에러가 타입에러 발견 된 적이 있어서

 

package.json파일에

 "resolutions": {
    "@types/react": "^18.0.0"
  },

 

resolutions로 버전을 위와 같이 맞춰주어서

해결한 적이 있습니다.

react next.js react-query next-auth msw

답변 2

1

제로초(조현영)

https://stackoverflow.com/questions/76898372/getting-type-element-is-not-assignable-to-type-reactnode-when-creating-a

여기에있는 방법들 시도해보세요. 코드 문제는 아닌 것 같습니다.

0

tittogam

감사합니다.
알려주신대로 버전을 최신버전으로 업그레이드 했더니 build에 성공했습니다.

 

캡처링부분 질문있습니다.

0

74

2

깃에 소스코드를 찾을 수 없습니다.

0

113

2

useInfiniteQuery promise와 react use 사용시 페이지 무한 로딩

0

98

1

import 파일 경로를 찾지 못 해서 에러가 발생합니다.

0

109

2

css 라이브러리 추천 부탁드립니다

0

140

2

팔로우 추천 목록이 빈 배열로 들어옵니다.

0

130

1

게시물 업로드 시 userId가 undefined로 들어가는 오류

0

119

1

useSuspenseQuery 사용 시 SSR 401 이슈 관련

0

171

1

리액트 쿼리 useinfinitequery 무한스크롤 구현 시 페이지가 이동할 경우 데이터가 보존되게 할 수 있나요??

0

184

3

폴링이 필요없는 이유

0

93

2

next Request Memoization과 react cache

0

108

2

seo 최적화 기준은 데이터 fetching인가요 아님 데이터 렌더링인가요?

0

84

2

next.js 서버fetch 에러 fallback ui 구현 방법

0

173

2

프레임워크 여론 파악법

0

125

2

필터옵션이 많은 페이지에서 서버 fetch를 하는게 맞는걸까요??

0

103

2

서버 fetch suspense 로 감싸고 새로고침 시 잠시 빈 화면이 노출된 후 fallback ui가 노출됩니다.

0

102

2

template.tsx 내 서버fetch 응답값과 클라이언트 컴포넌트 상태값 싱크가 맞지 않는 이슈

0

66

2

Auth.js 사용 시 authorize 함수가 호출되지 않습니다

0

131

2

next.js 에서 로그인에 관하여

0

138

1

Next의 route handler에 대한 질문이 있습니다.

0

101

2

게시판 리스트 만들때 use client를 어디서부터 집어넣어야할지 모르겠습니다

0

97

2

프라이빗 폴더를 해야 하는 이유가 모호한 것 같아요.

0

85

2

vanilla-extract 못찾는 문제

0

229

2

fetch 캐싱과 revalidate 관련

0

84

2