misc_pterodactyl-panel/resources/scripts/hoc/withFlash.tsx

24 lines
699 B
TypeScript
Raw Normal View History

2020-08-02 02:44:50 +00:00
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;