I have to different interface
interface Vehicle {// data about vehicle}interface Package {// data about package}
I have a component that in it's props can receive either of them (and maybe more in the future),so I created props interface as such:
interface Props<T> { modalVisible: boolean, selectableData: T[], currentlySelectedIndex: number, onSelect: (selection: T) => void, onBackPressed: () => void}
In my component I have a FlatList
that receives the selectableData
and a renderItem
function that like this:
<FlatList data={selectableData} renderItem={renderItem} style={{ maxHeight: 251 }} ItemSeparatorComponent={() => <FlatListItemSeparator separatorStyle= {styles.itemSeparator} />} keyExtractor={(item, index) => index.toString()} /> const renderItem: ListRenderItem<Vehicle | Package> = ({ item }) => (<ModalSelectionItem topText={ item instance Vehicle ? 'a' : 'b'} /> );
I want to render different text in the FlatList
based on type that was passed, how can I check what type of I have? I tried to use both instanceof
and typeof
but none of them seems to work