InterviewSolution
| 1. |
What is the significance of keys in a component in React Native? |
|
Answer» If you have EVER iterated through an array to create a list of component and in case you missed adding a key attribute with new elements, then React throws a warning that key is not assigned to elements. React USES Keys to identify unique Virtual Elements with their corresponding data driving the UI. They help React to optimise the rendering by recycling all the existing elements in the component. You can SAY that React uses these user given key values to identify the nodes. It makes a decision based on these keys whether the node should be updated or not. These keys must be a unique NUMBER or string, using which React just reorders the elements instead of re-rendering them. This leads to an increase in the application’s performance by REDUCING the number of elements manipulations. In case you don’t find any unique value to assign to a node, the last resort will be to assign key of the node equals to index of the item. |
|