-
Notifications
You must be signed in to change notification settings - Fork 84
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
Comments
I am also facing same issue |
I have the same problem. |
I use this design pattern and it seems to work reliably: const MyFuncComp = () => { However, the following does not always work: |
For what it's worth, the above design pattern works using: I just updated to using: |
Environment Details
Long Description
Version 0.18.1 changed the
ref
property to anonRef
callback. We useReactTabulator
in a functional component. The callback method I provide toonRef
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 tonull
. 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 theTableViewer
gets re-rendered which makes the refnull
again. That is why instead of selecting a row, the effect logs:tabulator invalid: null
.Workaround
Stay on 0.17.1 apparently.
The text was updated successfully, but these errors were encountered: