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

【React】Material-UI 導入 〜 運用手順

Last updated at Posted at 2020-11-04

Material-UIインストール

ターミナルの開発プロジェクト下で Material-UI の実装に必要なパッケージをインストールします

npm install --save @material-ui/core @material-ui/icons @material-ui/system

Material-UIインポート

Material-UI を使用したいファイル内で次をインポートします

import { makeStyles, createStyles } from '@material-ui/core/styles';

関数を定義

import下に次の関数を定義する

const useStyles = makeStyles(() =>
    createStyles({
        // ここでスタイルをつける
    }),
);

スタイルをつけよう

ルールとして以下の点に注意しましょう
・クラス、Id はダブルクォーテーションで囲む
・プロパティはキャメルケースでかく


//省略

const useStyles = makeStyles(() =>
    createStyles({
        "hello": {
            color: '#AAAAAA',
            fontWeight: 'bold',
        }
    }),
);

const Hello = () => {

    const classes = useStyles(); // useStyles関数を定数に代入
    return(
        <h1 className={classes.hello}>Hello World</h1> // クラスを指定する時は定数名.クラス名
    );
}

// 省略

以上

Material-UI公式ページ
https://material-ui.com/

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?