React hooks:将状态设置器作为参数传递给 onChange 函数?
我已经实现了。有用!但会不会很贵?如果它 那又如何呢?
const [neighbourCountryGeneraleDes, setNeighbourCountryGeneralDes] = useState(neighbour_country_generale_des_init);
const [neighbouringProvincePopulationSummary, setNeighbouringProvincePopulationSummary] = useState(neighbouring_province_population_summary_init);
const onChangeInput = (e, data, setData) => {
const { name, value } = e.target;
setData({ ...data, [name]: value });
};
JSX
<div style={{ marginBottom: "15px" }}>
<SearchInputField
width="785px"
headText="বন্দরের নাম"
icon={inputIcon}
bool={false}
placeholder="বন্দরের নাম লিখুন"
name="air_port_name"
value={neighbourCountryGeneraleDes.air_port_name}
handleChange={(e) => onChangeInput(e, neighbourCountryGeneraleDes,setNeighbourCountryGeneralDes)}
/>
</div>
I already implement that. It works! but could it be expensive ?? if it
is then how?
const [neighbourCountryGeneraleDes, setNeighbourCountryGeneralDes] = useState(neighbour_country_generale_des_init);
const [neighbouringProvincePopulationSummary, setNeighbouringProvincePopulationSummary] = useState(neighbouring_province_population_summary_init);
const onChangeInput = (e, data, setData) => {
const { name, value } = e.target;
setData({ ...data, [name]: value });
};
JSX
<div style={{ marginBottom: "15px" }}>
<SearchInputField
width="785px"
headText="বন্দরের নাম"
icon={inputIcon}
bool={false}
placeholder="বন্দরের নাম লিখুন"
name="air_port_name"
value={neighbourCountryGeneraleDes.air_port_name}
handleChange={(e) => onChangeInput(e, neighbourCountryGeneraleDes,setNeighbourCountryGeneralDes)}
/>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论