简体   繁体   English

为什么我不能为反应钩子分配输入值?

[英]Why I can't assign input value to react hook?

I want to get input value and assign it to react hook.我想获取输入值并将其分配给反应钩子。

const { specName, setSpecName } = useState("");

<input
          name="name"
          onChange={e => { setSpecName(e.target.value) }}
          value={specName}
          className="specialist-profile-input"
          type="text"
          placeholder={user.name} />
        <input type="submit" value="Save" />

When, I'm starting writing, pops up error "TypeError: setSpecName is not a function".当我开始写作时,弹出错误“TypeError:setSpecName 不是函数”。 I took a pattern from one guy and it's not working.我从一个人那里拿了一个模式,但它不起作用。 I don't know how to fix it.我不知道如何解决它。

Because the return value of useState cannot be destructured as an object.因为useState的返回值不能被解构为object。

const [specName, setSpecName] = useState("");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM