@@ -2,8 +2,8 @@ import React, { useCallback, useState } from 'react';
22import { render , fireEvent } from '@testing-library/react' ;
33import '@testing-library/jest-dom/extend-expect' ;
44import { useTable } from '../hooks' ;
5- import { ColumnType , RowType } from '../types' ;
6- import { makeData , UserType } from './makeData' ;
5+ import { ColumnType , RowType , DataType } from '../types' ;
6+ import { makeData } from './makeData' ;
77
88const columns = [
99 {
@@ -27,17 +27,12 @@ const data = [
2727 } ,
2828] ;
2929
30- type TestDataType = {
31- firstName : string ;
32- lastName : string ;
33- } ;
34-
35- const TableWithSelection = ( {
30+ const TableWithSelection = < T extends DataType > ( {
3631 columns,
3732 data,
3833} : {
39- columns : ColumnType [ ] ;
40- data : Object [ ] ;
34+ columns : ColumnType < T > [ ] ;
35+ data : T [ ] ;
4136} ) => {
4237 const { headers, rows, selectRow, selectedRows, toggleAll } = useTable (
4338 columns ,
@@ -122,14 +117,14 @@ test('Should be able to select rows', async () => {
122117 expect ( rtl . queryAllByTestId ( 'selected-row' ) ) . toHaveLength ( 0 ) ;
123118} ) ;
124119
125- const TableWithFilter = ( {
120+ const TableWithFilter = < T extends DataType > ( {
126121 columns,
127122 data,
128123 filter,
129124} : {
130- columns : ColumnType [ ] ;
131- data : TestDataType [ ] ;
132- filter : ( row : RowType < TestDataType > [ ] ) => RowType < TestDataType > [ ] ;
125+ columns : ColumnType < T > [ ] ;
126+ data : T [ ] ;
127+ filter : ( row : RowType < T > [ ] ) => RowType < T > [ ] ;
133128} ) => {
134129 const { headers, rows } = useTable ( columns , data , {
135130 filter,
@@ -171,20 +166,20 @@ test('Should be able to filter rows', () => {
171166 expect ( rtl . getAllByTestId ( 'table-row' ) ) . toHaveLength ( 1 ) ;
172167} ) ;
173168
174- const TableWithSelectionAndFiltering = ( {
169+ const TableWithSelectionAndFiltering = < T extends DataType > ( {
175170 columns,
176171 data,
177172} : {
178- columns : ColumnType [ ] ;
179- data : UserType [ ] ;
173+ columns : ColumnType < T > [ ] ;
174+ data : T [ ] ;
180175} ) => {
181176 const [ searchString , setSearchString ] = useState ( '' ) ;
182177 const [ filterOn , setFilterOn ] = useState ( false ) ;
183178
184179 const { headers, rows, selectRow, selectedRows } = useTable ( columns , data , {
185180 selectable : true ,
186181 filter : useCallback (
187- ( rows : RowType < UserType > [ ] ) => {
182+ ( rows : RowType < T > [ ] ) => {
188183 return rows . filter ( row => {
189184 return (
190185 row . cells . filter ( cell => {
0 commit comments