Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 带反应挂钩的摄氏至华氏转换器_Reactjs_React Hooks - Fatal编程技术网

Reactjs 带反应挂钩的摄氏至华氏转换器

Reactjs 带反应挂钩的摄氏至华氏转换器,reactjs,react-hooks,Reactjs,React Hooks,我正在尝试使用React挂钩对摄氏到华氏(以及反之亦然)的转换器进行编码。 但是双向数据绑定不起作用,我不明白为什么。 有人能帮忙吗? 谢谢 这是我的密码 function GradConverter(){ const [Cgrad, toC] = React.useState(null) const [Fgrad, toF] = React.useState(null) return( <div id="container"> <div id=

我正在尝试使用React挂钩对摄氏到华氏(以及反之亦然)的转换器进行编码。
但是双向数据绑定不起作用,我不明白为什么。
有人能帮忙吗?
谢谢

这是我的密码

function GradConverter(){

const [Cgrad, toC] = React.useState(null)
  const [Fgrad, toF] = React.useState(null)

  return(
    <div id="container">
      <div id="box1">
        <h1>Celsius</h1>
        <input
            type = "number"
            value = { Cgrad }
            onChange = {(event) => toF((event.target.value * 9 / 5) + 32).toFixed(2) } >
          </input>
      </div>
      <div id="box2">
          <h1>Fahrenheit</h1>
          <input
            type = "number" 
            value = { Fgrad } 
            onChange = {(event) => toC((event.target.value - 32) * 5 / 9).toFixed(2) } >
          </input>
          </div>
    </div>
  )
}
函数梯度转换器(){
常量[Cgrad,toC]=React.useState(null)
常量[Fgrad,toF]=React.useState(null)
返回(
摄氏度
toF((event.target.value*9/5)+32.toFixed(2)}>
华氏的
toC((event.target.value-32)*5/9.toFixed(2)}>
)
}

两个测量系统都需要一个状态,并且在发生变化时始终更新两个值:

函数梯度转换器(){
const[temp,updateTemp]=React.useState({f:0,c:0})
const updateec=ev=>updateTemp({
c:ev.target.value,
f:(+ev.target.value*9/5+32).toFixed(2)
})
const updateef=ev=>updateTemp({
c:(+ev.target.value-32)*5/9.toFixed(2),
f:ev.目标值
})
返回(
摄氏度
华氏的
)
}
ReactDOM.render(
,
根
)