mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 17:30:38 +08:00
Kill shouldItemUpdate
Summary:
It was just adding unnecessary complexity. Users should just use standard React perf best practices, like `PureComponent` and `shouldComponentUpdate`.
This should be backwards compatible - existing `shouldItemUpdate` usage will just be ignored and should consider migrating to this pattern:
```
class MyItem extends React.PureComponent {
_onPress = () => {
this.props.onPressItem(this.props.id);
};
render() {
return (
<SomeOtherWidget title={this.props.title} onPress={this._onPress} />
)
}
}
...
_renderItem = ({item}) => (
<MyItem onPressItem={this._onPressItem} title={item.title} id={item.id} />
);
```
Which will automatically prevent re-renders unless the relavent data changes.
Reviewed By: yungsters
Differential Revision: D4730599
fbshipit-source-id: 0f61efe96eb4d95bb3b7c4ec889e3e0e34436e56
This commit is contained in:
committed by
Facebook Github Bot
parent
72670bf8d2
commit
5c856150ff
@@ -107,7 +107,6 @@ class MultiColumnExample extends React.PureComponent {
|
||||
onRefresh={() => alert('onRefresh: nothing to refresh :P')}
|
||||
refreshing={false}
|
||||
renderItem={this._renderItemComponent}
|
||||
shouldItemUpdate={this._shouldItemUpdate}
|
||||
disableVirtualization={!this.state.virtualized}
|
||||
onViewableItemsChanged={this._onViewableItemsChanged}
|
||||
legacyImplementation={false}
|
||||
@@ -127,11 +126,6 @@ class MultiColumnExample extends React.PureComponent {
|
||||
/>
|
||||
);
|
||||
};
|
||||
_shouldItemUpdate(prev, next) {
|
||||
// Note that this does not check state.fixedHeight because we blow away the whole list by
|
||||
// changing the key anyway.
|
||||
return prev.item !== next.item;
|
||||
}
|
||||
// This is called when items change viewability by scrolling into or out of the viewable area.
|
||||
_onViewableItemsChanged = (info: {
|
||||
changed: Array<{
|
||||
|
||||
Reference in New Issue
Block a user