How to rerender some components but not all?

Viewed 980

I have an object coming from redux with a photo that I render in a react native class component.

Each time I update the state of the related class component for a different object, the image of the object coming from redux is reloading.

How could I avoid that?

I thought using redux would avoid to re render the object on state update.

1 Answers

Whenever the state of the component changes the component is re-rendered that is the basic ideology of react-native. You can put conditions in shouldComponentUpdate() to limit the number of times the component needs to re-render. This function allows you to conditionally re-render the component instead of re-rendering everytime when the state changes.

Here is the reference: https://facebook.github.io/react/docs/react-component.html#shouldcomponentupdate

For re-rendering a single element in a component you can use keys that should be unique for every sibling element in a component. React recognizes using these keys that which elements is changed and needs to be re-rendered instead of re-rendering the whole component.

Here is the reference: https://facebook.github.io/react/docs/lists-and-keys.html#keys

Related