Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- maxwidth
- package.json
- 플러그인
- 웹아이콘
- Git clone
- slickslider
- owlcarousel
- 의존성문제
- vscode git clone
- npm install 문제
- 아이콘사용법
- legacy-peer
- 글자들여쓰기
- fontawesome
- node설치
- MediaQuery
- 이미지반응형
- npm start
- XEIcon
- git lab clone
- react npm install
- 동적객체
- node 오류
- googleicon
- minwidth
- window 정책변경
- 단어단위로떨어지기
- 그누보드반응형
- npm install
- 정적객체
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
버튼 컴포넌트 1차 본문
728x90
버튼 컴포넌트
"use Client";
import { useRouter } from "next/navigation";
interface ButtonProps{
text: string;
onClick?: () => void;
href?: string;
className?: string;
}
export function Button({ text, onClick, href, className }: ButtonProps){
const router = useRouter();
// href가 있으면 버튼 클릭 시 페이지 이동
const handleCLick = () => {
if(onClick) onClick();
if(href) router.push(href);
};
return(
<button
type="button"
onClick={handleCLick}
className={`btn ${className || ""}`}
>
{text}
</button>
)
}
💻 props class 안전 처리
✔ className={`btn ${className}`}
렌더링 => class="btn undefined"
✔ className={`btn ${className || ""}`}
렌더링 => class="btn "
✔ clsx 라이브러리 사용
import clsx from "clsx";
className={clsx("btn", className)}
=> undefined, null, false 자동 무시 → 깔끔하게 클래스 합치기 가능
728x90
'개발 > 🔵 React-TypeScript' 카테고리의 다른 글
| 팝업 컴포넌트 2차 (외부 클릭시, esc 닫힘_useRef 사용) (0) | 2025.09.18 |
|---|---|
| 팝업 컴포넌트 1차 (0) | 2025.09.18 |
| 오류 검증 (0) | 2025.09.17 |
| Enter시 초점 이동, 함수 실행 (0) | 2025.09.17 |
| 전체선택 구현하기 (0) | 2025.09.16 |
Comments
