3
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】StackblitzでimgタグにUnsplashの画像が挿入できない

3
Posted at

はじめに

StackBlitzというWeb上の統合開発環境を使ってReactの学習中、imgタグに挿入する画像をUnsplashという画像のフリー素材サイトから取得しようとしたときに発生した問題。

問題

imgタグに「Unsplash」という画像のフリー素材を提供しているサイトから、ワンちゃんの画像を挿入しようとしたが反映されなかった。

スクリーンショット 2025-12-21 101126.png

export const UserCard = () => {
  return (
    <div>
      <img
        src="https://source.unsplash.com/dogs-face-2l0CWTpcChI"
        alt="プロフィール"
      />
      <p>名前</p>
      <dl>
        <dt>メール</dt>
        <dd>11111@aaa.com</dd>
        <dt>TEL</dt>
        <dd>000-9999-88888</dd>
        <dt>会社名</dt>
        <dd>ああああああ会社</dd>
        <dt>WEB</dt>
        <dd>htttttttt.com</dd>
      </dl>
    </div>
  );
};

解決方法

URLを「Lorem Picsum」というランダムにフリー画像が表示されるサイトに変更すると画像が表示されるようになりました。

どうやら「Unsplash」だとアクセスする時にブロックされるようです。

スクリーンショット 2025-12-21 102057.png

export const UserCard = () => {
  return (
    <div>
      <img
        src="https://fastly.picsum.photos/id/563/200/200.jpg?hmac=AUY3PTIdje13MIMulUogg4h4AYMKO4XfeEZQaEGw8fQ"
        alt="プロフィール"
      />
      <p>名前</p>
      <dl>
        <dt>メール</dt>
        <dd>11111@aaa.com</dd>
        <dt>TEL</dt>
        <dd>000-9999-88888</dd>
        <dt>会社名</dt>
        <dd>ああああああ会社</dd>
        <dt>WEB</dt>
        <dd>htttttttt.com</dd>
      </dl>
    </div>
  );
};

おわりに

ワンちゃんの画像にしたかった。。

image.png

3
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
3
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?