mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Memoize VirtualizedListCellContextProvider
Summary: When a FlatList is nested inside another FlatList, it may be re-rendered whenever the outer FlatList renders. Apply the same optimization we already had in `VirtualizedListContextProvider` to avoid changing the context object if no values have changed. Changelog: [General][Changed] - Optimized VirtualizedList context when used with nested lists Reviewed By: genkikondo Differential Revision: D35905952 fbshipit-source-id: 695253c85db2043d22e208ad94ecc7daa1455055
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f40976cd24
commit
ceb0a54608
@@ -142,10 +142,14 @@ export function VirtualizedListCellContextProvider({
|
||||
cellKey: string,
|
||||
children: React.Node,
|
||||
}): React.Node {
|
||||
const context = useContext(VirtualizedListContext);
|
||||
// Avoid setting a newly created context object if the values are identical.
|
||||
const currContext = useContext(VirtualizedListContext);
|
||||
const context = useMemo(
|
||||
() => (currContext == null ? null : {...currContext, cellKey}),
|
||||
[currContext, cellKey],
|
||||
);
|
||||
return (
|
||||
<VirtualizedListContext.Provider
|
||||
value={context == null ? null : {...context, cellKey}}>
|
||||
<VirtualizedListContext.Provider value={context}>
|
||||
{children}
|
||||
</VirtualizedListContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user