[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.
This commit is contained in:
Grzegorz Rozdzialik
2018-12-11 18:30:02 +01:00
parent 4c5e88a266
commit 8ef8a681c1
4 changed files with 9 additions and 8 deletions

View File

@@ -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<Props extends Partial<TableProps>>(
Component: ComponentType<Props>,
WrappedComponent: ComponentType<Props>,
options?: SelectTableHOCOptions
): ComponentType<Props & SelectTableAdditionalProps>;
): ComponentClass<Props & SelectTableAdditionalProps>;
export default selectTableHOC;

View File

@@ -1,9 +1,9 @@
import { ComponentType } from 'react';
import { ComponentType, ComponentClass } from 'react';
import { TableProps } from '../../index';
declare function treeTableHOC<Props extends Partial<TableProps>>(
Component: ComponentType<Props>
): ComponentType<Props>;
WrappedComponent: ComponentType<Props>
): ComponentClass<Props>;
export default treeTableHOC;

View File

@@ -52,6 +52,7 @@ ReactDOM.render(
{...selectTableAdditionalProps}
data={data}
columns={columns}
ref={React.createRef()}
/>,
document.getElementById('root')
);

View File

@@ -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(
<SelectTable data={data} columns={columns} />,
<TreeTable data={data} columns={columns} ref={React.createRef()} />,
document.getElementById('root')
);