File tree Expand file tree Collapse file tree
packages/jsapi-components/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments