Skip to content

Commit

Permalink
Add example to not render offscreen content (#38800)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38800

Changelog:
[General][Internal] - Add performance comparison example to not render offscreen content

Reviewed By: rshest

Differential Revision: D47892462

fbshipit-source-id: dd5bbd83c3baaf229c4b6fea89904cf4bb7b37de
  • Loading branch information
Xin Chen authored and facebook-github-bot committed Aug 21, 2023
1 parent 80685d5 commit 489d890
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/

'use strict';

import * as React from 'react';
import ItemList from '../components/ItemList';
import {LIST_100_ITEMS} from '../components/itemData';

const ItemListMemo = React.memo(ItemList);

function RenderOffscreenContentBadExample(): React.Node {
return <ItemListMemo data={LIST_100_ITEMS} />;
}

function RenderOffscreenContentGoodExample(): React.Node {
return (
<ItemListMemo useFlatList data={LIST_100_ITEMS} initialNumToRender={2} />
);
}

export default {
title: 'Do not render offscreen content',
description:
'Render long list with ScrollView vs FlatList + initialNumToRender prop.\nNever render offscreen content when not needed.',
Bad: RenderOffscreenContentBadExample,
Good: RenderOffscreenContentGoodExample,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
export {default as ReRenderWithNonPureChildExample} from './ReRenderWithNonPureChildExample';
export {default as ReRenderWithObjectPropExample} from './ReRenderWithObjectPropExample';
export {default as SetStateInWrongEffectExample} from './SetStateInWrongEffectExample';
export {default as RenderOffscreenContentExample} from './RenderOffscreenContentExample';

0 comments on commit 489d890

Please sign in to comment.