mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-19 06:43:45 +02:00
add withFlash() context HOC
This commit is contained in:
23
resources/scripts/hoc/withFlash.tsx
Normal file
23
resources/scripts/hoc/withFlash.tsx
Normal 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;
|
||||
Reference in New Issue
Block a user