💡 In bigger applications, parts are oftentimes not directly related, but need to communicate with each other somehow - instead of reaching out for Redux or useContext, we can return it as a promise.
Code
// hook.tsxexport const useActivateStatus = () => { return React.useCallback( async (isTrue: boolean): Promise<{ continueFlow: boolean }> => new Promise((resolve) => { if (isTrue) { return resolve({ continueFlow: true }); } return resolve({ continueFlow: false }); }), []);}// app.tsxconst activate = useActivateStatus(); // step i.React.useEffect(() => { const handleLogic = async () => { const status = await activate(true); if (status.continueFlow) { // do something here - step ii. } // else do something else }; handleLogic();}, [activate]);
Contact me
Send me a detailed message below and I'll get back to you as soon as possible.