ForEach
A function that allows you to map over an array to dynamically render a collection of views
function ForEach<T>(
iterable: T[],
renderFn: (element: T, index: number) => ReactElement<any>
): ReactElement<any, string | React.JSXElementConstructor<any>>[];
Example​
- swiftui-react-native
- SwiftUI
- React Native
const options = ['Option 1', 'Option 2', 'Option 3'];
<VStack>
{ForEach(options, (option, i) => (
<Text key={i}>{option}</Text>
))}
</VStack>
let options = ["Option 1", "Option 2", "Option 3"]
VStack {
ForEach(options, id: \.self) { option in
Text(option)
}
}
const options = ['Option 1', 'Option 2', 'Option 3'];
<View>
{options.map((option, i) => (
<Text key={i}>{option}</Text>
))}
</View>