我有一个input元素在监听一个事件,我如何将input的值传递给一个React State?const [business,setBusiness] = useState('Value should be entered here ') 〈input placeholder=“搜索企业”onChange={“pass the value”}/〉谢谢!
const [business,setBusiness] = useState('Value should be entered here ') 〈input placeholder=“搜索企业”onChange={“pass the value”}/〉
yzxexxkh1#
就像这样:
<input placeholder="Search Businesses" onChange={e => setBusiness(e.target.value)}/>
cgvd09ve2#
可以通过设置事件值来设置useState中的值,如下所示:
<input placeholder="Search Businesses" onChange={event => setBusiness(event.target.value)}/>
2条答案
按热度按时间yzxexxkh1#
就像这样:
cgvd09ve2#
可以通过设置事件值来设置useState中的值,如下所示: