inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Hướng dẫn tạo dịch vụ bản đồ bằng React + Express từ nhà phát triển Corona Map (Typescript)

Tạo Component chung - Button

styled component 버튼 타입에러

Đã giải quyết

498

grs0412

18 câu hỏi đã được viết

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

Câu trả lời 1

0

donghunee

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

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

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

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

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

 

/ide 명령어 실행 오류

0

2

1

Next.js 사전렌더링 이해하기 부분

0

3

1

subagents에 관한 질문이 있습니다.

0

7

1

클로드 코드 설치가 되지 않습니다...

0

12

1

output sytles 모든 프로젝트 적용시 디렉토리가 헷갈립니다 ㅠㅠ

0

14

1

터미널 줄바꿈 세팅

0

14

1

setting.json과 setting.local.json

0

16

1

카드 뉴스 만들기..

0

17

0

기존 mcp를 플러그인으로 대체

0

14

1

바이브코딩을 하는 개발자(작업복잡도 판단의 어려움)

0

15

1

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

0

115

2

보일러플레이트 코드 오류

0

206

2

수업자료 오류

0

156

1

MongoDB Compass 관련 질문

0

344

1

카카오 맵 api

0

269

1

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

0

208

1

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

0

177

1

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

0

335

1

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

0

942

2

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

0

392

1

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

0

528

1

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

1

484

1

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

0

397

1

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

1

492

1