let response = data?.is_signup ? await apiRequest.Auth.sendLoginOtp(data) : await apiRequest.Auth.login(data);
condition based i want trigger different api
let response = data?.is_signup ? await apiRequest.Auth.sendLoginOtp(data) : await apiRequest.Auth.login(data);
condition based i want trigger different api
2
Answers
You can handle API requests conditionally in React based on certain conditions. The code snippet you provided looks mostly correct, assuming data is the object containing the necessary parameters for your API requests and is_signup is a boolean value indicating whether it’s a signup operation or not.
you can call handleAPIRequest(data) whenever you need to make the API request, passing in the appropriate data object.
Make sure apiRequest.Auth.sendLoginOtp and apiRequest.Auth.login are defined correctly and return Promises, as await expects a Promise to be returned from an async function.
let response;
try {
return data.islogin ? await apiRequest.Auth.sendLoginOtp(data) :await apiRequest.Auth.login(data);;
} catch (e) {
return {
error: e
}
}
}