1.

Explain setNativeProps. Does it create Performance issues and how is it used ?

Answer»

It is sometimes necessary to make changes directly to a component without using state/props to trigger a re-render of the entire SUBTREE. When using REACT in the browser, for example, you sometimes NEED to directly modify a DOM node, and the same is true for views in mobile apps. setNativeProps is the React Native equivalent to setting properties directly on a DOM node.
Use setNativeProps when frequent re-rendering creates a performance bottleneck.

Direct manipulation will not be a tool that you reach for frequently; you will typically only be using it for creating continuous animations to avoid the OVERHEAD of rendering the component hierarchy and reconciling many views. setNativeProps is imperative and stores state in the native layer (DOM, UIView, etc.) and not WITHIN your React components, which makes your code more difficult to reason about. Before you use it, try to solve your problem with setState and shouldComponentUpdate.



Discussion

No Comment Found