Material-table: Trying to call onQueryChange(), but tableRef.current is always null

Created on 9 Sep 2020  路  3Comments  路  Source: mbrn/material-table

function InstanceTable() {
    const tableRef = React.createRef();
    const reloadTableData = () => {
       tableRef.current.onQueryChange();
    };

    return (
    <MaterialTable
      title="Instance"
      tableRef={tableRef}
      ...
    />
}

When reloadTableData is called, tableRef.current is null.

question

Most helpful comment

workaround:

Declare the ref as global, outside your main function.
image

All 3 comments

Same issue here!

workaround:

Declare the ref as global, outside your main function.
image

If you don't want a global ref: replace const tableRef = React.createRef(); with const tableRef = React.useRef(); instead. Worked for me.

Was this page helpful?
0 / 5 - 0 ratings