Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Last active September 13, 2020 06:23
Show Gist options
  • Save jmaicaaan/1cad98e7f4c25d9cc2b70f0aa9d1efc6 to your computer and use it in GitHub Desktop.
Save jmaicaaan/1cad98e7f4c25d9cc2b70f0aa9d1efc6 to your computer and use it in GitHub Desktop.
import React from 'react';
export const App = () => {
const {
data: data00,
error: error00,
execute: executeNext00AsyncCall,
} = executeNext00AsyncCall();
const {
data: data01,
error: error01,
execute: executeNext01AsyncCall(),
} = useNext01ApiCall();
const {
data: data02,
error: error02,
execute: executeNext02AsyncCall(),
} = useNext02AsyncCall();
const [isSubmitting, setIsSubmitting] = React.useState(false); // or use formik
const handleOnSubmit = (formValues) => {
setIsSubmitting(true);
executeNext00AsyncCall(formValues);
};
useEffect(() => {
if (data00 && !data01) { // if first API call have data and second API call doesn't have data yet
try {
executeNext01AsyncCall(data00);
} catch (error) {}
}
}, [
data00,
data01,
executeNext01AsyncCall,
]);
useEffect(() => {
if (data01 && !data02) { // if second API call have data and third API call doesn't have data yet
try {
executeNext02AsyncCall(data01);
} catch (error) {}
}
}, [
data01,
data02,
executeNext02AsyncCall,
]);
useEffect(() => {
if (data01 && data02 && data03) { // all calls have data
setIsSubmitting(false);
// redirect if needed using the response or do anything you want
}
}, [
data01,
data02,
data03
]);
return (
...
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment