I have explored whole web for the solution but nothing worked for me as expected. My Api's are being called twice, resulting in duplicating data in db. I want them to trigger just once.
Find the code below:
<Route
path="/apis/wallet_verification"
render={(routerProps) => {
//deals with some params
console.log("I am triggering");
axios.get(`http://website/apis/save_ride_payments?payment_type=WALLET`).then((saveRides) =>{
console.log("I am inside get");
axios.post(`http://website/apis/verify_token?token=${usertoken}`).then((response) => {
if(response.data.status !== "error") {
console.log("I am inside post");
routerProps.history.push({
pathname: '/paymentsuccess',
state: {initRide}
});
}
})
})
console.log("I am out");
return (
<div>
Wallet Transaction
</div>
)
}}
/>
Output of console:
I am triggering
I am out
I am inside get
I am triggering
I am out
I am inside post
I am inside get
I am inside post
Network tab is showing this Api sequence:
save_ride_payments
verify_token
save_ride_payments
verify_token
my index.js
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root'));
Definitely, there might be some logical mistake. Would love if someone were to point that out.