Skip to content

Commit

Permalink
state lift up!
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuharuokazaki committed Aug 30, 2021
1 parent 684be7f commit da4cb78
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
11 changes: 11 additions & 0 deletions src/boil.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

function BoilingVerdict(props){
if(props.celsius >= 100){
return <p>水は沸騰しました。</p>;
}

return <p>水は沸騰していません。</p>;
}

export default BoilingVerdict;
19 changes: 19 additions & 0 deletions src/calculator.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react"
import TempInput from "./tempinput"

class Calculator extends React.Component {


render(){

return(
<div>
<TempInput scale="c"/>
<TempInput scale="f"/>
</div>
)
}
}


export default Calculator;
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import Calculator from "./maindoc.jsx";
import Article from "./article";
import Calculator from "./calculator.jsx";



ReactDOM.render(
Expand Down
29 changes: 11 additions & 18 deletions src/maindoc.jsx → src/tempinput.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React from "react"
import React from "react";
import BoilingVerdict from "./boil";
const scaleNames = {
c:"Celcius",
f:"Fahrenheit"
};

function BoilingVerdict(props){
if(props.celsius >= 100){
return <p>水は沸騰しました。</p>;
}

return <p>水は沸騰していません。</p>;
}

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

handleChange(e){
Expand All @@ -21,22 +18,18 @@ class Calculator extends React.Component {

render(){
const temp = this.state.temp;
const scale = this.props.scale;
return(
<fieldset>
<legend>
摂氏で温度を入力してね!
</legend>
<legend>{scaleNames[scale]}で水温を入れてね:</legend>
<input
value={temp}
onChange={this.handleChange}
/>
<BoilingVerdict celsius={parseFloat(temp)}/>
</fieldset>

);
}
}



export default Calculator;
export default TempInput;

0 comments on commit da4cb78

Please sign in to comment.