ManagedTable: pass an innerRef to bypass debounceRender

Summary: The ref would point to the DebouncedComponent instead of the ManagedTable passing an innerRef and handling binding manually.

Reviewed By: mweststrate

Differential Revision: D22374912

fbshipit-source-id: d404931405939ef8bfbde31f9aec7d531a3b62e3
This commit is contained in:
Luc Oth
2020-07-03 09:33:09 -07:00
committed by Facebook GitHub Bot
parent 51e7ce3566
commit 7c3d264803
2 changed files with 18 additions and 1 deletions

View File

@@ -157,7 +157,7 @@ class SearchableManagedTable extends PureComponent<Props, State> {
filter={this.state.filterRows} filter={this.state.filterRows}
rows={rows.filter(this.state.filterRows)} rows={rows.filter(this.state.filterRows)}
onAddFilter={addFilter} onAddFilter={addFilter}
ref={innerRef} innerRef={innerRef}
/> />
); );
} }

View File

@@ -137,6 +137,12 @@ export type ManagedTableProps = {
* Whether to allow navigation via arrow keys. Default: true * Whether to allow navigation via arrow keys. Default: true
*/ */
enableKeyboardNavigation?: boolean; enableKeyboardNavigation?: boolean;
/**
* Reference to the managed table.
*/
innerRef?:
| React.MutableRefObject<ManagedTable | undefined>
| ((ref: ManagedTable | undefined) => void);
}; };
type ManagedTableState = { type ManagedTableState = {
@@ -209,10 +215,21 @@ export class ManagedTable extends React.Component<
componentDidMount() { componentDidMount() {
document.addEventListener('keydown', this.onKeyDown); document.addEventListener('keydown', this.onKeyDown);
if (typeof this.props.innerRef === 'function') {
this.props.innerRef(this);
} else if (this.props.innerRef) {
this.props.innerRef.current = this;
}
} }
componentWillUnmount() { componentWillUnmount() {
document.removeEventListener('keydown', this.onKeyDown); document.removeEventListener('keydown', this.onKeyDown);
if (typeof this.props.innerRef === 'function') {
this.props.innerRef(undefined);
} else if (this.props.innerRef) {
this.props.innerRef.current = undefined;
}
} }
UNSAFE_componentWillReceiveProps(nextProps: ManagedTableProps) { UNSAFE_componentWillReceiveProps(nextProps: ManagedTableProps) {