You can use the repeat formula to create dynamic lists or grids where items are repeated based on data.
The repeat formula allows you to create multiple instances of an element based on a set of values or a numeric range. It is useful for generating dynamic content where the number of repetitions is determined by your data.
The output of your formula must be iterable, that is an Array of items.
The repeatKey formula is optionally used in conjunction with repeat for optimization purposes, especially when working with a large number of repeated elements. It assigns a unique key to each repeated instance, enabling toddle to more efficiently re-render only the elements that have changed, rather than the entire set of repeated elements.
The repeatKey is also useful when elements swap positions (e.g. when using drag and drop to change the order of an array) to ensure our runtime knows if an item kan be reused across renders or not.
The output of the repeatKey formula should be a unique ID/string for each repeated item.
This approach reduces the computational overhead during updates, as toddle can track which items have changed and only re-render those items.