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
callbacks do not change across renders #111
Comments
the renderers/getters are called only if the data or columns changed, you can try to change the rowData to see if the getters re-called |
thanks for the prompt reply. it makes sense. what kind of changes to the data array trigger a refresh? I've tried with 'touching' both the array and the individual items but the This might illustrate. In a component: const random = ...generate a random something...
console.log(random)
return
<BaseTable width={200} height={200} data={[performance.now()]}>
<BaseColumn title="test" key={test} dataGetter={({rowData})=>{ console.log(random); return rowData}}/>
</BaseTable> the data changes at each render, yet the getter remains stuck at the first closure (continue to print the first random value) However if I change the column at each render, e.g: const random = ...generate a random something...
console.log(random)
return
<BaseTable width={200} height={200} data={["fixed"]}>
<BaseColumn title={`test-${performance.now()}`} key={test} dataGetter={({rowData})=>{ console.log(random); return rowData}}/>
</BaseTable> I do see new closures at each render, even if the data remains constant. Apologies in advance if this is all obvious to you. I didn't expect an optimisation on something that scales along with columns - not rows - nor do I find it intuitive to 'touch' the columns to force an update. Again, I might be missing something. thanks so far! |
for your first example, as you said it's in a closure, so it always print the first random value, but I believe the for your second example, the You don't need to touch the column definition to update the rows, simply update the data item, like |
thanks. to clarify:
that said, I'm reporting that making the data an array of objects with an 'id' prop (or using The only thing that works for me so far is to touch the column (not necessarily the |
I think you get something wrong, update the row item means you have to change the ref of the object, so data[0].value=newValue won’t work as the row item’s ref stays the same, also you have to change the ref of the data itself or React won’t know data state changed, that’s the law of React, you don’t need to change the key, and in most cases you shouldn’t For the closure problem, there is an open issue to track it, right now it’s recommended to pass the variable to the column definition and then access it from the render like cellRenderer=({ column }) => column.sameValue, we make it this way to avoid unnecessary re-rendering |
okay, my example seems to have complicated matters. |
As I said, if you want to use data out of the rowData or column, the data will keep stale as it’s in a closure and won’t get updated because of optimization, if you do have to use outside data/state, but then in the column definition and access it from the column param of the renderer, or you can use React.Context to break the short circuit |
See #11 FYI |
noted! let me sum up your advice.
a simpler alternative, at the cost of some extra rendering work, would be to put a it's working quite happily like this now. do you have a feel of how bad are the implications of touching one col this way at each render? |
In theory your solution works as your expectation, but for me it's not nature, I'd rather read all the necessary data from the renderer's params to eliminate the closure, adding a useless timestamp to the column is somehow tricky, I think |
BTW thanks for your patience to explain your use case, now I totally understand your problem here |
well, am building software on top of your effort and the time you take to explain it to people. thank you rather and keep up the good work! |
@nihgwu What is the recommended workaround for this issue? Context? |
pass any state used in renderer to any of the columns, and read it from |
@nihgwu we tried to avoid it, it feels hacky. Are you planning to address it in the future? |
@dufia sure, in the next major version we won't memoize the props too aggressively |
@nihgwu thanks a lot. Sorry to bother you with this question, do you have an idea when the next major release would be? |
Sorry I'm quite busy recently, maybe two months to go |
Hi, @nihgwu ! I think I'm facing the same issue when I'm trying to pass some async stuff to Can you help with any universal workaround for it until the next major release? |
Hi there,
I might be missing something obvious, but can I access render props from getters/renderers? My
dataGetter
cellRenderer
don't seem to update, even if they're declared as anonymous functions, and see the same initial props at each subsequent render. Intended?f
The text was updated successfully, but these errors were encountered: