table icon indicating copy to clipboard operation
table copied to clipboard

Data is not updating even if the data is mutated

Open dhamodharan-baskar-e3171 opened this issue 6 years ago • 3 comments

Need to perform sort action outside react table and just the pass the data to react table but i cant able to fine any props or function to trigger that update or to notify react-table to use the latest sorted data

You must immutably update the data object you are passing to react table or at the very least make a new copy of it

tannerlinsley avatar Feb 17 '20 16:02 tannerlinsley

I'm using onRowUpdate: (newData, oldData) => Then I'm cloning my react-table data this way: let data = {...myStore}. then, I'm updating data with the newData argument, then I'm dispatching an action to update my store with the new updated data but the table does not re-render with the new data, it stays the same.

Just tried out this way:

let data = myStore.myArray.map((currValue, index)=> {
    if(index !== newData.index) return currValue;
    return {
     ...newData
   }
});

Does not work either. I thought maybe it was because let data = {... state} is a shallow copy.

Edit Already working properly, both ways worked as expected. I was committing a mistake in the data provided to the table.

Androsv96 avatar Feb 20 '20 12:02 Androsv96

Correct. data must be a new object if you want the table to updated. oldData should not === your newData

tannerlinsley avatar Feb 21 '20 14:02 tannerlinsley