0
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 1 year has passed since last update.

[React]component使い方

Last updated at Posted at 2023-07-13

component

componentreactでいろんなところで使えます。

今回はモーダルをcomponentで作りましょう。



モーダル

<button>click!</button>
<div className="modal">
  <h4>名前</h4>
  <p>年齢</p>
  <p>性別</p>
</div>
.modal{
  margin-top : 20px;
  padding : 20px;
  background : #eee;
  text-align : left;
}

こんな感じですね。
1.png



component

App functionの中にあったhtmlを外部にfunctionを作って入れてください。
component名は英語の大文字で始まった方がいいです。

function App (){
  return (
    <div>
        <button>click!</button>
    </div>
  )
}

function Modal(){
  return (
    <div className="modal">
      <h4>名前</h4>
      <p>年齢</p>
      <p>性別</p>
    </div>
  )
}

これだけではhtmlが消えちゃいます。
funtionの名前をタグとして入れます。

function App (){
  return (
    <div>
        <button>click!</button>
        <Modal></Modal>
    </div>
  )
}

これで完成です。
モーダルの機能はここでかくにんしてください。
modal機能

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