前提・実現したいこと
React 初心者です。
抗菌薬の投与量を JASON が返してくれるアプリを作っております。
発生している問題・エラーメッセージ
チェックボックスが女性の場合、Ccr の値を、0.85 倍させたいのですが、
state を変化させることができません。
エラーとなってしまいます。
該当のソースコード
React
import React from "react";
import { render } from "react-dom";
import axios from "axios";
import GetJson from "./getjson";
import "./App.css";
class App extends React.Component {
constructor() {
super();
this.state = {
sex: "",
weight: "",
age: "",
cr: "",
result: ""
};
}
handleChange1 = e => {
const newValue = e.target.value;
const numValue = newValue.replace(/[^0-9]/g, "");
this.setState({ weight: numValue });
};
handleChange2 = e => {
const newValue = e.target.value;
const numValue = newValue.replace(/[^0-9]/g, "");
this.setState({ age: numValue });
};
handleChange3 = e => {
const newValue = e.target.value;
this.setState({ cr: newValue });
};
resultCcr = (e) => {
e.preventDefault();
const a = 140 - this.state.age;
const b = 72 * this.state.cr;
const c = this.state.weight / b;
const d = a * c;
this.setState({ result: d });
};
render() {
console.log(this.state.result);
return (
<div>
<form onSubmit={this.resultCcr}>
<h2> 抗菌薬 計算アプリ</h2>
<div>
<label>性別: </label>
<div> <select className="select"> <option value="男性">男性</option> <option value="女性">女性</option> </select> </div> </div> <div> <label> 体重: </label> <input className="weight" type="text" onChange={this.handleChange1} /> <label> kg </label> </div> <div> <label> 年令: </label> <input className="age" type="text" onChange={this.handleChange2} /> <label> 才 </label> </div> <div> <label> Cr: </label> <input className="cr" type="text" onChange={this.handleChange3} /> <label> mg/dL </label> </div> <button> CCr </button> <input className="ccr" type="text" value={Math.floor(this.state.result)} /> <label> ml/min </label> </form> <GetJson /> </div> );
}
}
render(<App />, document.getElementById("root"));
試したこと
if (this.state.sex =="女性"){
this.setState({result: result * 0.85 })
}
エラーとなってしまいます。
どなたか、ご教示頂ければ幸いでございます。
あなたの回答
tips
プレビュー