refactor(ui/tables): remove temp type

refactor/EE-4337/service-task-datatable
Chaim Lev-Ari 2023-08-19 20:31:00 +03:00
parent 92dd6ed7bc
commit 1e2dbd7778
2 changed files with 5 additions and 17 deletions

View File

@ -100,18 +100,3 @@ export function createPersistedStore<T extends BasicTableSettings>(
)
);
}
/** this class is just a dummy class to get return type of createPersistedStore
* can be fixed after upgrade to ts 4.7+
* https://stackoverflow.com/a/64919133
*/
class Wrapper<T extends BasicTableSettings> {
// eslint-disable-next-line class-methods-use-this
wrapped() {
return createPersistedStore<T>('', '');
}
}
export type CreatePersistedStoreReturn<
T extends BasicTableSettings = BasicTableSettings
> = ReturnType<Wrapper<T>['wrapped']>;

View File

@ -2,7 +2,7 @@ import { useMemo, useState } from 'react';
import { useStore } from 'zustand';
import { useSearchBarState } from './SearchBar';
import { BasicTableSettings, CreatePersistedStoreReturn } from './types';
import { BasicTableSettings, createPersistedStore } from './types';
export type TableState<TSettings extends BasicTableSettings> = TSettings & {
setSearch: (search: string) => void;
@ -11,7 +11,10 @@ export type TableState<TSettings extends BasicTableSettings> = TSettings & {
export function useTableState<
TSettings extends BasicTableSettings = BasicTableSettings
>(store: CreatePersistedStoreReturn<TSettings>, storageKey: string) {
>(
store: ReturnType<typeof createPersistedStore<TSettings>>,
storageKey: string
) {
const settings = useStore(store);
const [search, setSearch] = useSearchBarState(storageKey);