Skip to content

Commit ce1fe2c

Browse files
authored
feat: useTableUtils hook (#1281)
resolves #1280
1 parent be82b14 commit ce1fe2c

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { ApiContext } from '@deephaven/jsapi-bootstrap';
3+
import dh from '@deephaven/jsapi-shim';
4+
import { TableUtils } from '@deephaven/jsapi-utils';
5+
import { renderHook } from '@testing-library/react-hooks';
6+
import useTableUtils from './useTableUtils';
7+
8+
const wrapper = ({ children }) => (
9+
<ApiContext.Provider value={dh}>{children}</ApiContext.Provider>
10+
);
11+
12+
it('should return a TableUtils instance based on the current dh api context', () => {
13+
const { result } = renderHook(() => useTableUtils(), { wrapper });
14+
expect(result.current.dh).toBe(dh);
15+
expect(result.current).toBeInstanceOf(TableUtils);
16+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useMemo } from 'react';
2+
import { useApi } from '@deephaven/jsapi-bootstrap';
3+
import { TableUtils } from '@deephaven/jsapi-utils';
4+
5+
/**
6+
* Get a `TableUtils` instance using `dh` api from the current context.
7+
*/
8+
export default function useTableUtils(): TableUtils {
9+
const dh = useApi();
10+
return useMemo(() => new TableUtils(dh), [dh]);
11+
}

0 commit comments

Comments
 (0)