Help us understand the problem. What is going on with this article?

React propsとsteat

個人メモ

propsとstate

Propsは属性の値を取得する

  constructor(props){
    super(props);
    this.state = {
      msg: 'Hello Component.',
    };
  }
ReactDOM.render(
  <React.StrictMode>
    <App msg="Hello App."/>
  </React.StrictMode>,
  document.getElementById('root')
);

上記ではstateとpropsを定義しています.
この中のpropsだけを取得.

<p>{this.props.msg}</p>

# これで Hello App.  が取得できる

stateを取得

<p>{this.state.msg}</p>

# これで Hello Component.  が取得できる

まとめ

・propsは属性を定義した値を取得(例:<App msg="Hello App."/>)
・stateはthis.stateで定義した値を取得(例:this.state ={msg: 内容})

参考

https://qiita.com/kyrieleison/items/78b3295ff3f37969ab50

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away