LoginSignup
0
2

More than 5 years have passed since last update.

react 復習

Posted at

わかる事
1 基本的に処理は変動しないモノにはfuncsionコンポーネント 変動するやつはclassコンポーネント
2 input イベント 出力 inputの周りの部分
補足
fieldsetはinputをグループ化する

import React from 'react';
import ReactDOM from 'react-dom';
import './ShippingList.css';

// import App from './App';
import * as serviceWorker from './serviceWorker';

function BoilingVerdict(props) {
  if (props.celsius >= 100) {
    return <p>The water would boil.</p>;
  }
  return <p>The water would not boil.</p>;
}



class Calculator extends React.Component {
  constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.state = {temperature: ''};
  }

  handleChange(e) {
    this.setState({temperature: e.target.value});
  }

  render() {
    const temperature = this.state.temperature;
    return (
      <fieldset>
        <legend>Enter temperature in Celsius:</legend>
        <input
          value={temperature}
          onChange={this.handleChange} />

        <BoilingVerdict
          celsius={parseFloat(temperature)} />

      </fieldset>
    );
  }
}

ReactDOM.render(<Calculator />  , document.getElementById('root'));



// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();



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