React Native - Force ListView Re-render when data has not changed

后端 未结 5 1118
后悔当初
后悔当初 2020-12-30 08:07

Is it possible to force a ListView to re-render, even if the data in the dataSource has not changed? I have a ListView within a tab bar in my app and I want it to redraw eve

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 08:28

    Use an Immutability Approach

    The best way to "update" this would be to clone the data item in question rather than doing a flag hack as the r1 !== r2 is already hinting at. Instead of updating an individual item, change the "pointer" itself by cloning.

    For this particular issue update the item in the array like so.

    arr[i] = { ...arr[i], someKey: newValue }
    

    This will replace the "someKey" property with "newValue" and the current row will have a new pointer.

    Here is a good resource to learn about immutability in modern JavaScript that react native uses: https://wecodetheweb.com/2016/02/12/immutable-javascript-using-es6-and-beyond/

提交回复
热议问题