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

APi call and render text result

$
0
0

Below is the call to the api and the console.log returns what I want, but I want to return the result in the <Text>{callOnmoTermsApi}</Text> The error I am getting is

Warning: Functions are not valid as a React child.

When I change the Text to a Button and console.log the onPress action it also shows what I want! Please help!!!

import { NavigationState } from '@react-navigation/routers';import React, { useState } from 'react';import { SafeAreaView, Text } from 'react-native';import { NavigationParams, NavigationSwitchProp } from 'react-navigation';import { onmoTerms } from '@/api/authApi';import OnmoButton from '@/components/Buttons/OnmoButton';interface Props {  navigation: NavigationSwitchProp<NavigationState, NavigationParams>;}const OnmoTermsAndCond = () => {  const [terms] = useState('');  const callOnmoTermsApi = () => {    onmoTerms()      .then((resp: any) => {        if (resp.statusCode === 200) {          console.log('terms ', resp);        }        setTimeout(() => {          console.log('timeout terms ', resp);        }, 500);      })      .catch((error) => {        console.log(error);      });  };  return (<SafeAreaView><Text>{callOnmoTermsApi}</Text></SafeAreaView>  );};export default OnmoTermsAndCond;

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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