summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/lib
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-06-29 14:50:23 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-07-01 11:37:48 +0200
commitd3636bb84afea9e7a9b786bf9ad4fd26951950a8 (patch)
tree6f235be5a3e9eeb86c3a90395f0b24484ed26c37 /gui/src/renderer/lib
parente6d83cc9fe4b8e951403bc3ee6d0744934b041ee (diff)
downloadmullvadvpn-d3636bb84afea9e7a9b786bf9ad4fd26951950a8.tar.xz
mullvadvpn-d3636bb84afea9e7a9b786bf9ad4fd26951950a8.zip
Add hook and HOC for our history implementation
Diffstat (limited to 'gui/src/renderer/lib')
-rw-r--r--gui/src/renderer/lib/history.tsx (renamed from gui/src/renderer/lib/history.ts)18
1 files changed, 18 insertions, 0 deletions
diff --git a/gui/src/renderer/lib/history.ts b/gui/src/renderer/lib/history.tsx
index c3a06b98e3..13968e29b9 100644
--- a/gui/src/renderer/lib/history.ts
+++ b/gui/src/renderer/lib/history.tsx
@@ -1,4 +1,6 @@
import { Location, Action, LocationDescriptor } from 'history';
+import React from 'react';
+import { RouteComponentProps, useHistory as useReactRouterHistory, withRouter } from 'react-router';
export interface ITransitionSpecification {
name: string;
@@ -178,3 +180,19 @@ export default class History {
return Math.random().toString(36).substr(8);
}
}
+
+export function useHistory(): History {
+ return useReactRouterHistory() as History;
+}
+
+export interface IHistoryProps {
+ history: History;
+}
+
+export function withHistory<P>(BaseComponent: React.ComponentType<P & IHistoryProps>) {
+ return withRouter((props: P & RouteComponentProps) => {
+ const history = props.history as History;
+ const mergedProps = ({ ...props, history } as unknown) as P & IHistoryProps;
+ return <BaseComponent {...mergedProps} />;
+ });
+}