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

Showing API response after calling it

$
0
0

I am calling an api end point that should render some information. I am calling the API but need an event to trigger it. I am triggering that event with a setTimeout function.

Although nothing is rendering, I am getting an error of Cannot read property state of undefined

This is the code:

const TermsAndCond = () => {  const [terms] = useState('');  const callTerms = () => {    Terms({ terms: terms })      .then((resp: any) => {        if (resp.statusCode === 200) {          setTimeout(() => {            ({ callTerms: resp });          }, 1000);        }        console.log('Data time', resp);      })      .catch((error: any) => {        console.log(error);      });  };  return (<><SafeAreaView><Text>Terms & Conditions</Text><Button title='hellow' onPress={callTerms} /></SafeAreaView></>  );};

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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