In React Native, rendering a component inside a loop is a common pattern used to display lists of data. Instead of traditional loops like for, React uses array methods such as map() to dynamically generate UI components.
map() is the preferred method for loopskeyReact Native does not allow direct looping inside JSX. Instead, JavaScript expressions are embedded inside JSX using curly braces. The map() function returns a new array of components.
// Rendering components in a loop using map()
import React from "react";
import { View, Text } from "react-native";
const Item = ({ value }) => (
{value}
);
export default function App() {
const items = ["Apple", "Banana", "Cherry"];
return (
{items.map((item, index) => (
-
))}
);
}
The array items is looped using map(). For each value, the Item component is rendered. The screen will display:
Add items below to see how the Data Array (Source) is instantly mapped to UI Components (Output).
Note: Every time you add data, React runs map() and creates a new component.
key propFlatList for large datasets (better performance)Text with styled componentsFlatList