【发布时间】:2021-11-21 10:03:46
【问题描述】:
我试图引用一个异步函数,但它却被执行了。
const Payment = props => {
const [buttonAction, setButtonAction] = useState(null);
useEffect(() => {
if(some true stuff){
// this gets executed instead of being a reference to a function
setButtonAction(() => createSubscription(a ? b : c ));
}
}, [deps...]);
const createSubscription = async (sessionId) => {
// code
}
}
【问题讨论】:
标签: javascript reactjs asynchronous