From 8ef8a681c189f424c30ea3a0061b2d2449e4d7e3 Mon Sep 17 00:00:00 2001 From: Grzegorz Rozdzialik Date: Tue, 11 Dec 2018 18:30:02 +0100 Subject: [PATCH] [react-table] allow using refs after applying HOCs The return type of HOCs did not match the reality. The return type was `ComponentType` which allowed StatelessComponent (which does not allow refs by default) to be returned, whereas in reality it was always the class component (`ComponentClass`) that was returned from a HOC. --- types/react-table/lib/hoc/selectTable.d.ts | 6 +++--- types/react-table/lib/hoc/treeTable.d.ts | 6 +++--- types/react-table/test/select-table-tests.tsx | 1 + types/react-table/test/tree-table-tests.tsx | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/types/react-table/lib/hoc/selectTable.d.ts b/types/react-table/lib/hoc/selectTable.d.ts index fd6d9bf42c..d1fc5d8392 100644 --- a/types/react-table/lib/hoc/selectTable.d.ts +++ b/types/react-table/lib/hoc/selectTable.d.ts @@ -1,4 +1,4 @@ -import { ComponentType } from 'react'; +import { ComponentType, ComponentClass } from 'react'; import { TableProps } from '../../index'; @@ -49,8 +49,8 @@ export interface SelectTableHOCOptions { } declare function selectTableHOC>( - Component: ComponentType, + WrappedComponent: ComponentType, options?: SelectTableHOCOptions -): ComponentType; +): ComponentClass; export default selectTableHOC; diff --git a/types/react-table/lib/hoc/treeTable.d.ts b/types/react-table/lib/hoc/treeTable.d.ts index 35d1522119..e696ceda02 100644 --- a/types/react-table/lib/hoc/treeTable.d.ts +++ b/types/react-table/lib/hoc/treeTable.d.ts @@ -1,9 +1,9 @@ -import { ComponentType } from 'react'; +import { ComponentType, ComponentClass } from 'react'; import { TableProps } from '../../index'; declare function treeTableHOC>( - Component: ComponentType -): ComponentType; + WrappedComponent: ComponentType +): ComponentClass; export default treeTableHOC; diff --git a/types/react-table/test/select-table-tests.tsx b/types/react-table/test/select-table-tests.tsx index a4ed4d4f25..fe4ee5c694 100644 --- a/types/react-table/test/select-table-tests.tsx +++ b/types/react-table/test/select-table-tests.tsx @@ -52,6 +52,7 @@ ReactDOM.render( {...selectTableAdditionalProps} data={data} columns={columns} + ref={React.createRef()} />, document.getElementById('root') ); diff --git a/types/react-table/test/tree-table-tests.tsx b/types/react-table/test/tree-table-tests.tsx index a099124c61..6bb9461f78 100644 --- a/types/react-table/test/tree-table-tests.tsx +++ b/types/react-table/test/tree-table-tests.tsx @@ -4,7 +4,7 @@ import * as ReactDOM from 'react-dom'; import ReactTable, { Column } from 'react-table'; import treeTableHOC from 'react-table/lib/hoc/treeTable'; -const SelectTable = treeTableHOC(ReactTable); +const TreeTable = treeTableHOC(ReactTable); const data = [{ id: 1, name: 'Foo' }, { id: 2, name: 'Bar' }]; @@ -14,6 +14,6 @@ const columns: Column[] = [ ]; ReactDOM.render( - , + , document.getElementById('root') );