LoginSignup
1
0

More than 3 years have passed since last update.

Reactでコンポーネント作成した際のメモ

Posted at

コンポーネントしたtsxファイル

import RequiredLabel from '../atoms/RequiredLabel';

export type TitleLabelProps = {
  name: string;
  styles: SerializedStyles;
}

export const TitleLabel: React.FC<TitleLabelProps> = (
  props,
) => (
    <div
        css={css`
            display: flex;
            align-items: center;
            line-height: 1;
        `}
    >
        <RequiredLabel />
        <div css={css`
      font-size: 14px;
      ${props.styles};
    `}>{props.name}</div>
    </div>
);
export default TitleLabel;

上記コンポーネントしたファイルをimportして呼び出してるファイルの記載

<TitleLabel 
            name={'きなこ'}
            styles={css`
              color: hotpink;
            `} />

TitleLabelの中で再度cssを追加することができている
なぜか→コンポーネントしたtsxの中で
styles: SerializedStyles;と
${props.styles};
で型をわたしてるから

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0