add withFlash() context HOC

This commit is contained in:
Dane Everitt 2020-08-01 19:44:50 -07:00
parent b92c97060b
commit 0c7f118f45
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 30 additions and 6 deletions

View file

@ -0,0 +1,23 @@
import React from 'react';
import useFlash from '@/plugins/useFlash';
import { Actions } from 'easy-peasy';
import { ApplicationStore } from '@/state';
export interface WithFlashProps {
flash: Actions<ApplicationStore>['flashes'];
}
function withFlash<TOwnProps> (Component: React.ComponentType<TOwnProps & WithFlashProps>): React.ComponentType<TOwnProps> {
return (props: TOwnProps) => {
const { addError, addFlash, clearFlashes, clearAndAddHttpError } = useFlash();
return (
<Component
flash={{ addError, addFlash, clearFlashes, clearAndAddHttpError }}
{...props}
/>
);
};
}
export default withFlash;