Skip to content

Commit

Permalink
Add a shallowEqual to DataProvider callback
Browse files Browse the repository at this point in the history
  • Loading branch information
amadeus committed Mar 27, 2024
1 parent b0057e2 commit 1adac87
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/FlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ import {
updateContentStyle,
} from "./utils/ContentContainerUtils";

function shallowEqual(a: any, b: any) {
if (a === b) {
return true;
}
if (a == null || b == null) {
return a == b;
}

const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (keysA.length !== keysB.length) {
return false;
}
for (let i = 0; i < keysA.length; i++) {
const key = keysA[i];
if (a[key] !== b[key]) {
return false;
}
}
return true;
}

interface StickyProps extends StickyContainerProps {
children: any;
}
Expand Down Expand Up @@ -217,7 +239,7 @@ class FlashList<T> extends React.PureComponent<
data: null,
layoutProvider: null!!,
dataProvider: new DataProvider((r1, r2) => {
return r1 !== r2;
return !shallowEqual(r1, r2);
}, getStableId),
numColumns: 0,
};
Expand Down

0 comments on commit 1adac87

Please sign in to comment.