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?

【React × BootstrapでSVGアイコンをコンポーネント化して使う方法】

Posted at

今回は Bootstrapのアイコンをimgで挿入するのではなく、コンポーネント化して使う方法をやったので、忘れないように備忘録として残します。

SVGをReactで使うメリット(拡大しても劣化しない、スタイル変更が簡単)
ではなく のように使えると再利用性が高まる!

1ライブラリのインストール

npm install react-bootstrap-icons

または

yarn add react-bootstrap-icons

2使い方:アイコンをインポートして使う

import { Twitter } from "react-bootstrap-icons";

function SocialIcons() {
  return (
    <div style={{ fontSize: "2rem", display: "flex", gap: "16px" }}>
      <Twitter />
    </div>
  );
}

これでBootstrapのアイコン一覧にあるツイッターの青い鳥アイコンを簡単に使える!!
下記の公式サイトにたくさん載ってるのでぜひ探して使ってみてください!
https://icons.getbootstrap.com/
例えば一番左上の⓪ってアイコンが使いたいなってときは、
「0 circle」って名前なので、スペースはくっつけて、キャメル式にすればコンポーネント化できる!

import { 0Circle } from "react-bootstrap-icons";

function SocialIcons() {
  return (
    <div style={{ fontSize: "2rem", display: "flex", gap: "16px" }}>
      <0Circle />
    </div>
  );
}
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?