UNPKG

@janiscommerce/ui-native

Version:
22 lines (21 loc) 829 B
import React from 'react'; import { FlatList, ScrollView } from 'react-native'; export var TypeList; (function (TypeList) { TypeList["FlatList"] = "flatList"; TypeList["ScrollView"] = "scrollView"; })(TypeList || (TypeList = {})); const List = ({ data, renderComponent, type = TypeList.FlatList, ...props }) => { if (!data?.length) { return null; } if (type === TypeList.ScrollView) { const scrollProps = props; return (<ScrollView {...scrollProps}> {data.map((item, index) => renderComponent({ item, index }))} </ScrollView>); } const cleanedFlatProps = props; return (<FlatList data={data} renderItem={({ item, index }) => renderComponent({ item, index })} keyExtractor={(item, index) => String(item.id ?? index)} {...cleanedFlatProps}/>); }; export default List;