万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    React native getInitialState

    var Hello = React.createClass({
      getDefaultProps: function() {
        return {name: "Default Props"};
      },
    
      render: function() {
        return <div>Hello {this.props.name}</div>;
      }
    });

    みたいなコードのgetDefaultPropsをクラスでやる時どうするのかな?

    reactjs - What is the difference between using constructor vs getInitialState in React / React Native? - Stack Overflow

    コンストラクタでやるらしい。 constructorを使う。

    class Hello extends React.Component {
      constructor(props) {
        super(props);
        console.log(props);
        console.log(this.props);
        this.state = {name: this.props.initialName};
      }
    
      render() {
        return <div>Hello {this.state.name}</div>;
      }
    }
    Hello.defaultProps = {initialName: "Default Props"};