5. props와 attrs
1. Props
사용 방법
import { useBoolean } from 'usehooks-ts';
import styled, { css } from 'styled-components';
type ParagraphProps = {
active?: boolean;
}
const Paragraph = styled.p<ParagraphProps>`
color: ${(props) => (props.active ? '#F00' : '#888')};
${(props) => props.active && css`
font-weight: bold;
`}
`;
export default function Greeting() {
const { value: active, toggle } = useBoolean(false);
return (
<div>
<Paragraph>Inactive</Paragraph>
<Paragraph active>Active</Paragraph>
<Paragraph active={active}>
Hello, world
{' '}
<button type="button" onClick={toggle}>
Toggle
</button>
</Paragraph>
</div>
);
}2. attrs
.attrs
사용 방법
Last updated