-
-
Save SangeetAgarwal/0c6152c1da1a5917020e32a6a29de6ef to your computer and use it in GitHub Desktop.
Skeletal of the presentation component that receives data as props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ResourceEdit = ({ | |
resource, | |
mappedCategories, | |
mappedCategoryContentAreas, | |
mappedTopics, | |
}: { | |
resource: DataAccess.ResourceApiModel; | |
mappedCategories: { [key: string]: string }; | |
mappedCategoryContentAreas: { [key: string]: string }; | |
mappedTopics: { [key: string]: string }; | |
}) => { | |
React.useEffect(() => { | |
setSafeCategoryContentAreas(mappedCategoryContentAreas); | |
setSafeCategories(mappedCategories); | |
setSafeTopics(mappedTopics); | |
return function cleanup() { | |
}; | |
}, [resource, mappedTopics, mappedCategories, mappedCategoryContentAreas]); | |
const validate = (values: IFormFields) => { | |
}; | |
const onSubmit = async ( | |
values: IFormFields, | |
actions: FormikHelpers<IFormFields> | |
) => { | |
await retry( | |
async (bail) => { | |
try { | |
await axios(config); | |
} catch (e) { | |
const error = e as AxiosError; | |
if ( | |
error.response && | |
(error.response.status === 400 || | |
error.response.status === 401 || | |
error.response.status === 403) | |
) { | |
bail(e); | |
} else { | |
throw e; | |
} | |
}, | |
{ retries: 3 } | |
); | |
// then, mutate to refresh cached resource | |
mutate(["/api/resource", values.id as string]); | |
}; // OnSubmit Ends | |
const onReset = (values: IFormFields) => { | |
// These are outside the purview of formik so need to manage these manually | |
}; | |
// Formik hook | |
const formikBag = useFormik({ | |
initialValues, | |
validate, | |
onSubmit, | |
onReset, | |
enableReinitialize: true, | |
}); | |
return ( | |
<> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment