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

displaying only one entry with useQuery

$
0
0

I'm trying to just display one value from a query and I'm wondering why the first snippet of code does not display the name while the other one does

this one does not work:

const EXCHANGE_RATES = gql`  query {    profiles (limit: 1){        id        name  }}`;export const ExchangeRates: React.FC<ExchangeRatesProps> = () => {    const { loading, error, data } = useQuery(EXCHANGE_RATES);    if (loading) return <Text>Loading...</Text>;    if (error) return <Text>Error :(</Text>;    return  (<View ><Text>                {data.profiles.name}</Text></View>    );}

but this one does:

export const EXCHANGE_RATES = gql`  query {    profiles (limit: 1){        id        name  }}`;export const ExchangeRates: React.FC<ExchangeRatesProps> = () => {    const { loading, error, data } = useQuery(EXCHANGE_RATES);    if (loading) return <Text>Loading...</Text>;    if (error) return <Text>Error :(</Text>;    return data.profiles.map(({ id, name} : {id:number, name:string}) => (<View ><Text>                {id} : {name}</Text></View>    ));}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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