1
1

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

Reactメモ

Posted at

Reactの個人的なメモです。

Reactとは?

・Facebookが開発したJSライブラリ(≠フレームワーク)

・WebのUI(ユーザーインターフェイス)
 1.見た目(View)
 2.機能(Controller)

・仮想DOMを操作できる

通常DOM

 document.getElementById('hoge').innerText = 'fuga' 

仮想DOM

 render(
<div id = 'hoge'>fuga</div>
)

JSX

React内で使うHTMLの様なJSの拡張言語(仮想DOMで使う言語)

通常DOM

const fuga = "<h1>Hello,World!</h1>"
const foo = "<h2>React Commentary</h2>"
const bar = "Hi, I'm Taro"
document.getElementById('hoge').innerHTML = fuga
document.getElementById('foo').innerHTML = foo
document.getElementById('bar').innerText = bar

JSX

return(
  <React.fragment>
   <div id = "hoge">
    <h1>Hello,World!</h1>
   </div>
   <div id = "bar">
    <h2>React Commentary</h2>
   </div>
   <p id = "foo">Hi,I'm Taro</p>
  </React.fragment>
);

JSXの基礎文法


Reactパッケージのインストール
.JSXファイルの先頭で宣言

import React from "react"


変数名はキャメルケースで書く
classNameなど文字を繋ぐときは大文字で


classはclassNameに変える

const App = () =>{
  return(
    <div id = "hoge" className = "fuga">
      <h1>Hello, World!</h1>
    </div>
  );
};


{}内に変数や関数を埋め込める

const foo = "<h1>Hello, World!</h1>"
const App = () =>{
  return(
    <div id = "hoge" className = "fuga">
      {foo} 
    </div>
  );
};

5
空要素は必ず閉じる

const App = () =>{
  return(
    <div id = "hoge" className = "fuga">
      <input type="text" id = "blankElement"/> #閉じる
      <img src="/assets/icon/foo.png"/> #閉じる
    </div> 
  );
};
1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?