-
[React] props에 따라 스타일 설정하기Frontend/React 2022. 9. 21. 19:09
버튼 컴포넌트에 props로 상태 넘겨주기
import Button from '../../components/Button'; <Button onClick={emailVerifiedClick} disabled={loading} styling={fullBtn} text={loading ? '이메일 전송중' : '이메일 재전송'} />
상태에 따라 스타일링 하기
import { classNames } from '../shared/share'; interface IProps { type?: 'submit' | 'button'; text: string; onClick?: () => void; disabled?: boolean; styling?: 'fullBtn' | 'normal'; } export default function Button({ type = 'button', text, onClick, disabled, styling, }: IProps) { return ( <button type={type} onClick={onClick} disabled={disabled} className={classNames( `px-5 py-3 bg-indigo-600 hover:bg-indigo-700 text-white rounded-sm text-sm cursor-pointer disabled:bg-indigo-200`, styling === 'fullBtn' && `flex w-full justify-center disabled:bg-indigo-200` )} > {text} </button> ); }
반응형'Frontend > React' 카테고리의 다른 글
[React] 프론트엔드에서 PWA 적용하기 (0) 2023.07.31 [프론트엔드] 카카오 소셜 로그인 연동하기(with REST API) (0) 2023.07.10 [Next.js] Image, background-image 삽입하는 방법을 알아보자 (0) 2022.09.05 [React Hook Form] radio button 구현하기 (0) 2022.07.10 [React Router v6] Nested Routes에 대해 알아보자 (0) 2022.05.12