在完成ReactJ中功能组件的一组状态变量设置后,如何调用功能
function check(){
const [variable, setvariable1] = useState(0);
const [variable2, setvariable2] = useState(0);
const [variable3, setvariable3] = useState(0);
const last_func = () => {
console.log("call this function")
}
const mainfunction = () =>{
setvariable(1);
setvariable2(1);
setvariable3(1);
last_func(); //this function needs to be called after completing above all state variables
}
}
我想在完成所有状态变量的设置为1之后致电last_func
function check(){
const [variable, setvariable1] = useState(0);
const [variable2, setvariable2] = useState(0);
const [variable3, setvariable3] = useState(0);
const last_func = () => {
console.log("call this function")
}
const mainfunction = () =>{
setvariable(1);
setvariable2(1);
setvariable3(1);
last_func(); //this function needs to be called after completing above all state variables
}
}
i want call the last_func after completing the setting of all state variables to 1 then only i have to call that last_func
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另外,如果您想在所有变量为'0之后自动运行last_fun,则可以使用使用效率:
also if you want to run last_fun automatically after all variables are >0 you can use useEffect: