diff --git a/src/VariableSizeGrid.js b/src/VariableSizeGrid.js
index f2b8aaa..950c627 100644
--- a/src/VariableSizeGrid.js
+++ b/src/VariableSizeGrid.js
@@ -396,20 +396,28 @@ const VariableSizeGrid = createGridComponent({
rowMetadataMap: {},
};
- instance.resetAfterColumnIndex = (columnIndex: number) => {
- this.resetAfterIndices({ columnIndex });
+ instance.resetAfterColumnIndex = (
+ columnIndex: number,
+ shouldForceUpdate?: boolean = true
+ ) => {
+ this.resetAfterIndices({ columnIndex, shouldForceUpdate });
};
- instance.resetAfterRowIndex = (rowIndex: number) => {
- this.resetAfterIndices({ rowIndex });
+ instance.resetAfterRowIndex = (
+ rowIndex: number,
+ shouldForceUpdate?: boolean = true
+ ) => {
+ this.resetAfterIndices({ rowIndex, shouldForceUpdate });
};
instance.resetAfterIndices = ({
columnIndex,
rowIndex,
+ shouldForceUpdate = true,
}: {
columnIndex?: number,
rowIndex?: number,
+ shouldForceUpdate?: boolean,
}) => {
if (typeof columnIndex === 'number') {
instanceProps.lastMeasuredColumnIndex = Math.min(
@@ -429,7 +437,10 @@ const VariableSizeGrid = createGridComponent({
// It seems an unnecessary optimization.
// It's unlikely that resetAfterIndex() will be called while a user is scrolling.
instance._itemStyleCache = {};
- instance.forceUpdate();
+
+ if (shouldForceUpdate) {
+ instance.forceUpdate();
+ }
};
return instanceProps;
diff --git a/src/VariableSizeList.js b/src/VariableSizeList.js
index d7737f2..6475c23 100644
--- a/src/VariableSizeList.js
+++ b/src/VariableSizeList.js
@@ -251,7 +251,10 @@ const VariableSizeList = createListComponent({
lastMeasuredIndex: -1,
};
- instance.resetAfterIndex = (index: number) => {
+ instance.resetAfterIndex = (
+ index: number,
+ shouldForceUpdate?: boolean = true
+ ) => {
instanceProps.lastMeasuredIndex = Math.min(
instanceProps.lastMeasuredIndex,
index - 1
@@ -262,7 +265,10 @@ const VariableSizeList = createListComponent({
// It seems an unnecessary optimization.
// It's unlikely that resetAfterIndex() will be called while a user is scrolling.
instance._itemStyleCache = {};
- instance.forceUpdate();
+
+ if (shouldForceUpdate) {
+ instance.forceUpdate();
+ }
};
return instanceProps;
diff --git a/src/__tests__/VariableSizeGrid.js b/src/__tests__/VariableSizeGrid.js
index b89ce81..4568a4c 100644
--- a/src/__tests__/VariableSizeGrid.js
+++ b/src/__tests__/VariableSizeGrid.js
@@ -206,6 +206,19 @@ describe('VariableSizeGrid', () => {
});
describe('resetAfterIndex method', () => {
+ it('should not call forceUpdate if shouldForceUpdate is false', () => {
+ const rendered = ReactTestRenderer.create(
+
- VariableSizeGrid caches offsets and measurements for each
- column index for performance purposes. This method clears that cached
- data for all columns after (and including) the specified index. It
- should be called whenever a column's width changes. (Note that this is
- not a typical occurrance.)
-
- VariableSizeGrid caches offsets and measurements for each
- item for performance purposes. This method clears that cached data for
- all items after (and including) the specified indices. It should be
- called whenever an items size changes. (Note that this is not a typical
- occurrance.)
-
+ VariableSizeGrid caches offsets and measurements for each
+ column index for performance purposes. This method clears that cached
+ data for all columns after (and including) the specified index. It
+ should be called whenever a column's width changes. (Note that this is
+ not a typical occurrance.)
+
+ You can set shouldForceUpdate to false
+ to prevent the list calling forceUpdate internally.
+
- VariableSizeGrid caches offsets and measurements for each
- row index for performance purposes. This method clears that cached data
- for all rows after (and including) the specified index. It should be
- called whenever a row's height changes. (Note that this is not a typical
- occurrance.)
-
+ VariableSizeGrid caches offsets and measurements for each
+ item for performance purposes. This method clears that cached data for
+ all items after (and including) the specified indices. It should be
+ called whenever an items size changes. (Note that this is not a
+ typical occurrance.)
+
+ You can set shouldForceUpdate to false
+ to prevent the list calling forceUpdate internally.
+
+ VariableSizeGrid caches offsets and measurements for each
+ row index for performance purposes. This method clears that cached
+ data for all rows after (and including) the specified index. It should
+ be called whenever a row's height changes. (Note that this is not a
+ typical occurrance.)
+
+ You can set shouldForceUpdate to false
+ to prevent the list calling forceUpdate internally.
+
- VariableSizeList caches offsets and measurements for each
- index for performance purposes. This method clears that cached data for
- all items after (and including) the specified index. It should be called
- whenever a item's size changes. (Note that this is not a typical
- occurrance.)
-
+ VariableSizeList caches offsets and measurements for each
+ index for performance purposes. This method clears that cached data
+ for all items after (and including) the specified index. It should be
+ called whenever a item's size changes. (Note that this is not a
+ typical occurrance.)
+
+ You can set shouldForceUpdate to false
+ to prevent the list calling forceUpdate internally.
+