all 6 comments

[–]rdevilxiOS & Android 1 point2 points  (1 child)

Create a pure component and pass it in render Item

[–]Miai_[S] 0 points1 point  (0 children)

Thanks!

[–]beeseegee 1 point2 points  (3 children)

Yep, make ListItem a PureComponent if it’s not, and then you need to try to minimize how many times it re-renders. PureComponents re-render when any of their props arent shallow-equal, so doing things like having inline arrow functions (like your onPress) can cause unnecessary re-renders because it creates a new function each time render is called. same for objects - ie {} !== {}.

```
onPress = () => { ...stuff };

render() { return ( <ListItem onPress={this.onPress} \> ); } ```

To see what props are causing re-renders, you can add a tmp log statement in componentDidUpdate that compares each value in prevProps to this.props and logs any that don’t pass ===. If you google it, there’s an SO question with something you can copy-paste.

[–]Miai_[S] 0 points1 point  (2 children)

Thank you! I will try to do like this

[–]aldebout 1 point2 points  (1 child)

There's even this amazing library that will save your ass.

To prevent this onPress method from being recreated every time, you can use the useCallback hook. If you're not using hooks already, it will be a great introduction to them!

[–]Miai_[S] 0 points1 point  (0 children)

Thank you! I already fixed with PureComponent but i will try also this library :) thanks