Skip to content

Instantly share code, notes, and snippets.

@alieslamifard
Created February 28, 2019 13:41
Show Gist options
  • Save alieslamifard/ee2a307e32b960bf8bd977a03db98dc7 to your computer and use it in GitHub Desktop.
Save alieslamifard/ee2a307e32b960bf8bd977a03db98dc7 to your computer and use it in GitHub Desktop.
export function async someAction() {
const response = await someHelperFunctionThatCallAnotherService();
if (!response) {
return dispatch({
type: 'FAILURE'
})
}
// check schema
const schema = yup.object().required().shape({
bar: yup.array().required().shape({
hey: yup.string().required()
}
),
});
const isSchemaValid = await schema.isValid(response);
if ( !isSchemaValid ) {
return dispatch({
type: 'NOT_VALID'
})
}
return dispatch({
type: 'SUCCESS',
data: response
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment