LoginSignup
0
0

More than 3 years have passed since last update.

【React】 props を使ってみる

Last updated at Posted at 2020-11-28

はじめに

React を習得するまでの軌跡をメモっていく備忘録的な記事です。

props を使ってみる

index.js
import React from 'react';
import ReactDOM from 'react-dom';

const User = (props) => {
  return (
    <p>私の名前は{props.name}です。</p>
  )
};

ReactDOM.render(
    <User name={'太郎'} />,
  document.getElementById('root')
);

スクリーンショット 2020-11-29 0.00.28.png

表示成功

まとめ

  • コンポーネントの引数に props と入れる。

  • コンポーネントの中では props.hoge という形で props の値が取り出せる。

  • コンポーネントへの渡し方は \<Hoge hoge={値} />

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