mattermost-mobile/app/hooks/use_tabs/use_tabs.ts
Daniel Espino García 6c53533080
Standardize tabs across different components (#8691)
* Standardize tabs across different components

* Add tests and minor fixes

* Remove unneeded tests

* Add missing change

* Fix test

* Refactor to remove the component from the hook

* Rename hasDot for requiresUserAttention.

* Apply the changes to scheduled posts

* Fix texts

* Fix tests and fix minor style issue on iOS

* Fix filter positioning

* Fix some e2e tests

* Fix tests

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2025-05-28 16:23:37 +02:00

27 lines
866 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {useCallback, useMemo, useState, type ComponentProps} from 'react';
import type Tabs from './tabs';
import type {TabDefinition} from './types';
function useTabs<T extends string>(defaultTab: T, tabs: Array<TabDefinition<T>>, changeCallback?: (value: T) => void, testID?: string) {
const [tab, setTab] = useState(defaultTab);
const handleTabChange = useCallback((value: T) => {
setTab(value);
changeCallback?.(value);
}, [changeCallback]);
const tabsProps = useMemo<ComponentProps<typeof Tabs>>(() => ({
tabs,
selectedTab: tab,
onTabChange: handleTabChange,
testID,
}), [tabs, tab, handleTabChange, testID]);
return [tab, tabsProps] as const;
}
export default useTabs;