¿Cómo puedo agregar dos declaraciones de devolución a mi gancho useEffect ? Me gustaría agregar un detector de eventos a mi enlace actual.
Oyente de eventos:
const subscription = AppState.addEventListener("change", nextAppState => { if ( appState.current.match(/inactive|background/) && nextAppState === "active" ) { console.log("App has come to the foreground!"); } appState.current = nextAppState; setAppStateVisible(appState.current); console.log("AppState", appState.current); }); return () => { subscription.remove(); };Gancho actual:
useEffect(() => { async function checkRefresh() { if ( daysDiffToNow(lastUpdatedTimestamp) > 0 && appState.current.match(/inactive|background/) && nextAppState === "active" ) { await onRefreshAppData(); } } checkRefresh(); const updateLastUpdatedTextCallback = (value) => { setState((prevState) => ({ ... })); }; const id = setInterval(() => { updateLastUpdatedTextCallback(lastUpdatedTimestamp); }, TIME_INTERVAL_IN_MILISECONDS); return () => clearInterval(id); }, [lastUpdatedTimestamp]); const close = () => { setState((prevState) => ({ ... })); };Simplemente podría ponerlos de arriba a abajo dentro de useEffect y tener una función de return que se vería así (ejecuta a la vez el código para las dos declaraciones de retorno necesarias):
return () => { subscription.remove(); // the first clearInterval(id); // the second }