Parameters
An array of data items to iterate over.
A function that creates a view for each data item.
A structure that computes views on demand from an underlying collection of data.
ForEach<T>(data: T[], content: (item: T, index: number) => Component): Component;
ForEach<T>(subviews: Component, content: ({ subview: T }) => Component): Component;
VStack([
ForEach(["Apple", "Banana", "Cherry"], (fruit, index) =>
Text(fruit)
)
])
VStack({ spacing: 10 }, [
ForEach(users, (user, index) =>
HStack({ spacing: 12 }, [
Circle()
.fill(Color("gray"))
.frame({ width: 40, height: 40 }),
VStack({ alignment: "leading" }, [
Text(user.name).font("headline"),
Text(user.email).font("caption")
])
])
.padding()
.background(Color("white"))
.cornerRadius(8)
)
])