4
3

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 3 years have passed since last update.

【React】Youtubeのロード中に表示されるスケルトンを実装したい【MaterialUI】

Posted at

こんな感じのやつを実装したい

youtubeでどうがを読み込んでいる際に下記のようなロード状態になると思います。 このロード状態を表すMaterialUIのスケルトンを今回は実装していきます。

image.png

実装例

実装方法は意外とシンプル。 下記のように、MaterialUIの部品をimportして、どんな形で置くかを指定するvariantとWidthとheightをざっくり指定すればOK。 公式ページからコードを引用しました。
skelton
import React from 'react';
import Skeleton from '@material-ui/lab/Skeleton';

export default function Variants() {
  return (
    <div>
      <Skeleton variant="text" />
      <Skeleton variant="circle" width={40} height={40} />
      <Skeleton variant="rect" width={210} height={118} />
    </div>
  );
}

上記のコードだと、下記のような表示になります。
variantの指定によって、形が丸や四角、テキストタイプになるので、自分の実装したい形で指定すると良いでしょう。

image.png

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?