inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

코로나맵 개발자가 알려주는 React + Express로 지도서비스 만들기 (Typescript)

Common 컴포넌트 - Button 생성

styled component 버튼 타입에러

해결된 질문

512

grs0412

작성한 질문수 18

0

import { ReactNode } from "react";
import { Link } from "react-router-dom";
import styled from "styled-components";

interface ButtonProps {
  children?: ReactNode;
  onClick: (e: any) => void;
  type?: "link" | "button";
  url?: string;
}

const StyledButton = styled.button<ButtonProps>`
  outline: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
`;

function Button({ children, onClick, type = "button", url }: ButtonProps) {
  const RealButton = <StyledButton onClick={onClick}>{children}</StyledButton>;

  const RealLink = (
    <StyledButton onClick={() => {}}>
      <Link to={url!}>{children}</Link>
    </StyledButton>
  );
  return <div></div>;
}

export default Button;

강의를 보고 진행하던중에 RealLink에서 타입오류나 가서 확인을 해보니

button onClick이 없으면 styled componenet에서 에러를 내는 것 같습니다. 링크로 쓰면 onClick이벤트를 전달해주면 안될 것 같은데 ()=>{} 이처럼 의미없는 함수를 넘겨주면 될까요

react node.js mongodb express typescript

답변 1

0

이동훈

grs0412님 질문 남겨주셔서 감사합니다:)

해당 onClick을 required하게 설정을 해놔서 생기는 타입 에러인 것 같습니다.

interface ButtonProps { 
 children?: ReactNode; 
 onClick?: (e: any) => void; 
 type?: "link" | "button"; 
 url?: string; 
}

다음과 같이 onClick 메소드를 optional하게 받아주시기 바랍니다.

다시한번 질문 남겨주셔서 감사합니다.

 

유니티 제외 설치한 프로그램들 및 파일 삭제 방법

0

9

1

깃허브에서 콤피유아이 매니저 설치하는게 안됩니다.

0

10

2

"enableAllProjectMcpServers": true 추가를 실패했습니다 대안으로 아래와 같이 넣어도 될까요

0

11

1

커서에서 >install 'cursor'가 없습니다!

0

16

1

[7/1 업데이트 내역 공유] /agents 명령어 remove

0

22

1

vscode 클로드코드 에서 스크린샷 복붙(첨부)가 안됩니다.

0

19

1

한국어 설정

0

24

1

사진 복사 붙여넣기 관련 질문

0

23

2

eslint.config.js 설정 질문입니다.

0

14

2

7강 흐름 제어 아키택쳐 코드 순서

1

20

1

수업자료 다운로드 시 빈폴더만 나오네요

0

131

2

보일러플레이트 코드 오류

0

221

2

수업자료 오류

0

171

1

MongoDB Compass 관련 질문

0

356

1

카카오 맵 api

0

283

1

mongodb 및 mongoose 초기 세팅에서 다운로드 질문입니다

0

221

1

보일러 플레이트 다운 시 빈 폴더

0

189

1

지도가 두개가 열리는 것 같습니다

0

343

1

Node.js 버전 차이로 인한 오류 발생(추정)

0

949

2

[참고] 서버 보일러 플레이트에 axios 없네요~

0

401

1

초기 보일러플레이트 설정문제

0

534

1

serach.ts 파일 질문드립니다.

1

492

1

강의자료 소스코드 질문드립니다.

0

414

1

맵 클릭 이벤트 추가 강의와 Jotai 강의 순서에 대해 건의드립니다.

1

503

1