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.

Reactでのイベント,スタイルの扱い方

Posted at

はじめに

Reactでのイベント,スタイルの扱い方を学んだので,アウトプットしていきます.

イベント

  • Reactで,HTMLタグ内にイベントやCSSを書くときは,キャメルケース(小文字始まり,つなぎ文字のはじめを大文字)を使用する.例えばonClick
  • イベントには,JavaScriptの関数を指定できる.
  • HTMLタグの中でJavaScriptを書くときは,{}で囲って,JavaScriptということを明示する必要がある.
export const App = () => {
  return <button onClick={alert()}>ボタン</button>;
};

スタイル

  • ReactでHTMLにスタイルを当てる場合,タグ内にstyle={}のように書く.{}部分に,JavaScriptのオブジェクトとしてCSSを記述する.
  • JavaScriptのオブジェクトであるため,font-sizeのような-付きのプロパティは許容されていない.fontSizeのように,キャメルケースを使用する.
  • オブジェクトの値であるため,color : redのように,そのまま文字列を割り当てることはできない.color : 'red'と記述する.
export const App = () => {
  return <h1 style={{ fontSize: "18px" }}>こんにちは</h1>;
};
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?