mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-18 13:33:51 +00:00
Moved mercure hub binding from custom hook to HOC
This commit is contained in:
26
src/mercure/helpers/boundToMercureHub.tsx
Normal file
26
src/mercure/helpers/boundToMercureHub.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React, { FC, useEffect } from 'react';
|
||||
import { CreateVisit } from '../../visits/types';
|
||||
import { MercureInfo } from '../reducers/mercureInfo';
|
||||
import { bindToMercureTopic } from './index';
|
||||
|
||||
export interface MercureBoundProps {
|
||||
createNewVisit: (visitData: CreateVisit) => void;
|
||||
loadMercureInfo: Function;
|
||||
mercureInfo: MercureInfo;
|
||||
}
|
||||
|
||||
export function boundToMercureHub<T = {}>(
|
||||
WrappedComponent: FC<MercureBoundProps & T>,
|
||||
getTopicForProps: (props: T) => string,
|
||||
) {
|
||||
return (props: MercureBoundProps & T) => {
|
||||
const { createNewVisit, loadMercureInfo, mercureInfo } = props;
|
||||
|
||||
useEffect(
|
||||
bindToMercureTopic(mercureInfo, getTopicForProps(props), createNewVisit, loadMercureInfo),
|
||||
[ mercureInfo ],
|
||||
);
|
||||
|
||||
return <WrappedComponent {...props} />;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user