0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SVGファイルをReactコンポーネントとして使う時の備忘録

Last updated at Posted at 2022-10-30

はじめに

  • フロントエンド開発(React/TypeScript利用)で、簡単にSVGファイルを扱う方法のメモ。

SVGファイルを用意する

SVGファイルをReactコンポーネントとして使う

  • VSCodeなどでSVGファイルの中身を参照し、以下のようなファイルを作成する。
Icon.tsx
export const Icon = (props: {
  width?: number | string;
  height?: number | string;
  style?: React.CSSProperties;
}) => {
  return (
    <svg
      xmlns="..."
      width={props.width}
      height={props.height}
      viewBox="..."
    >
      <path
        fill="..."
        opacity="..."
        d="..."
      />
      ...
    </svg>
  );
};

参考文献

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?