Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onRef set to null in functional component after re-render #258

Open
FlorianHockmann opened this issue Apr 21, 2022 · 4 comments
Open

onRef set to null in functional component after re-render #258

FlorianHockmann opened this issue Apr 21, 2022 · 4 comments

Comments

@FlorianHockmann
Copy link

Environment Details

  • react-tabulator version: 0.18.1
  • OS: Ubuntu 20.04.4 LTS
  • Node.js version: v14.19.1

Long Description
Version 0.18.1 changed the ref property to an onRef callback. We use ReactTabulator in a functional component. The callback method I provide to onRef gets called with a valid ref which looks good at first. But then our functional component gets re-rendered which resets the internal ref variable where I stored the ref we got from the callback to null. So, we don't have a valid ref anymore when we try to call a method on it.

Demo with code sandbox

Working version with 0.17.1 which still took a ref: https://codesandbox.io/s/react-tabulator-onref-workingwithref-r8nxd1

and then I tried to update it to 0.18.1 and use onRef instead:
https://codesandbox.io/s/react-tabulator-onref-brokenwithonref-i6mwl1

The idea is that I want to handle selection of rows from outside the table. I did this for the simple example with two buttons. If you click them in the working example, then the rows get selected.
With onRef this doesn't work however as the TableViewer gets re-rendered which makes the ref null again. That is why instead of selecting a row, the effect logs: tabulator invalid: null.

Workaround

Stay on 0.17.1 apparently.

@RiteshParyali
Copy link

I am also facing same issue

@ajc-uconn
Copy link

I have the same problem.

@ScottTyson
Copy link

I use this design pattern and it seems to work reliably:

const MyFuncComp = () => {
const tableRef = React.useRef(null);
<ReactTabulator onRef={(r) => (tableRef.current = r.current)} />
}

However, the following does not always work:
<ReactTabulator onRef={(r) => (tableRef = r) } />

@ScottTyson
Copy link

For what it's worth, the above design pattern works using:
"react-tabulator": "^0.18.1",
"tabulator-tables": "^5.5.1",
HOWEVER, I am getting console errors related to getComponent() calls.

I just updated to using:
"react-tabulator": "^0.19.0",
"tabulator-tables": "^5.5.2",
The console errors are now gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants