Instead of writing something like:
let backHandlerSubscription: NativeEventSubscription | null = null;
const sub = (dispatch: Dispatch<Message>): void => {
backHandlerSubscription = BackHandler.addEventListener("hardwareBackPress", handler);
};
return [cmd.ofSub(sub), () => backHandlerSubscription?.remove()];
Write:
const sub = (dispatch: Dispatch<Message>): () => void => {
const backHandlerSubscription = BackHandler.addEventListener("hardwareBackPress", handler);
return () => backHandlerSubscription.remove()
};
return [cmd.ofSub(sub)];