Reputation: 4640
We do not use redux or saga and use services instead, for making API calls and storing data. Consider that there is a button that will make an async call when clicked.
render() {
return (
<Button onPress={() => {await this.requestOtp()}} text="Get OTP" />
);
}
Upvotes: 0
Views: 1744
Reputation: 1196
Render can not be async you can pass the async to componentDidMount or use hooks
Upvotes: 0
Reputation: 21
Try to use hooks:
import React, { useState } from 'react';
function MyComponent(){
let [output, updateOutput] = useState(null);
async function asyncFunction(){
// call here
let response = await this.requestOtp();
updateOutput(response.data);
}
return <Button onPress={asyncFunction} text={output} />
}
Upvotes: 1