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

How do I pass a Type to a statelles component in TypeScript

$
0
0

Well, I would like to use one component to render differents types of data, since im using typescript, i need to pass the type of data my flatlist will be using, by now, i only have music and playlist. Is there a way to pass these types by father? Because i would like to reuse these component

User type

type playlistType = {    id: string    name: string    user: userType}

Playlist type

type playlistType = {    id: string    name: string    user: userType}

Music type

type musicType = {    id: string    name: string    artist: string    album: string    releaseyear: Date    genre: string    duration: string    user: userType}

The Component

const scrollableView: React.FC<scrollableViewProps> = (props /* There is nothing coming to props yet */) => {    return (<FlatList <Type of data that cames>            /* The settings for flatlist */        />    )}

The Father component that will call the list twice

const Dashboard: React.FC<DashboardScreenProps> = ({navigation}) => {    let {loggedUser} = useContext(UserContext)    let [fetchedData, setFetchedData] = useState<fetchedDataType>({        playlists: [],        musics: []    })    /* Some code here thats not important */    return (<View style={Style.container}><View><Text>Playlists</Text><ScrollableView /> //The component I would like to pass playlist type</View><View><Text>Musics</Text><ScrollableView /> //The same component I would like to pass music type</View></View>    )}

Viewing all articles
Browse latest Browse all 6214

Trending Articles



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