mattermost-mobile/app/hooks/navigation_button_pressed.ts
Daniel Espino García cff12f7182
Enable exhaustive deps in the repo (#9508)
* Enable exhaustive deps in the repo

* Add tests for the new hooks

* Update claude.md

* Remove pre-commit overwrite
2026-02-18 11:56:16 +01:00

27 lines
969 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {type DependencyList, type EffectCallback, useEffect} from 'react';
import {Navigation} from 'react-native-navigation';
type Callback = EffectCallback | (() => Promise<void>);
const useNavButtonPressed = (navButtonId: string, componentId: string, callback: Callback, deps?: DependencyList) => {
useEffect(() => {
const unsubscribe = Navigation.events().registerComponentListener({
navigationButtonPressed: ({buttonId}: { buttonId: string }) => {
if (buttonId === navButtonId) {
callback();
}
},
}, componentId);
return () => {
unsubscribe.remove();
};
// The dependencies should be passed by the caller.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
};
export default useNavButtonPressed;