Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

React native component as typed model prop

$
0
0

I am trying to make a class that looks like this

export default class IconModel {    name: string    title: string    iconType: "AntDesign" | "Ionicons"    component: React.Component //What type should be used?    iconName: string    size: number}

What I want is to make the component prop only be able to be passed a react component (ex: Home.tsx)

I am then using it like this

import { HomeScreen } from '../../../screens';var iconData: IconModel[] = [    {        component: HomeScreen,        iconName: "appstore1",        iconType: "AntDesign",        ...<NavigationContainer><BottomTab.Navigator initialRouteName={INITIAL_ROUTE_NAME}>            {iconData.map((x, key) => (<BottomTab.Screen                        name={x.name}                        component={x.component}                        options={{                            title: x.title,                            tabBarIcon: ({ focused }) => <TabBarIcon focused={focused} data={x} />,                        }}                    />            ))}</BottomTab.Navigator></NavigationContainer>

Are you able to type a variable or prop as a JSX/React component?


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>