summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2024-03-19 11:02:37 +0100
committerOskar Nyberg <oskar@mullvad.net>2024-03-20 11:02:29 +0100
commitfb83478902398545f2b2ec721d838c5cbf51b1ab (patch)
tree11ec95b18dfbc20cb84dbe241abadae742f5deee /gui/src
parent625a7874ec2341a268a67162b4d6af3e804d7473 (diff)
downloadmullvadvpn-fb83478902398545f2b2ec721d838c5cbf51b1ab.tar.xz
mullvadvpn-fb83478902398545f2b2ec721d838c5cbf51b1ab.zip
Add hook for forcing a rerender in a component
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/renderer/lib/utilityHooks.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/gui/src/renderer/lib/utilityHooks.ts b/gui/src/renderer/lib/utilityHooks.ts
index 8c3925762e..81a5579dd6 100644
--- a/gui/src/renderer/lib/utilityHooks.ts
+++ b/gui/src/renderer/lib/utilityHooks.ts
@@ -69,3 +69,12 @@ export function useNormalBridgeSettings() {
const bridgeSettings = useSelector((state) => state.settings.bridgeSettings);
return bridgeSettings.normal;
}
+
+// This hook returns a function that can be used to force a rerender of a component, and
+// additionally also returns a variable that can be used to trigger effects as a result. This is a
+// hack and should be avoided unless there are no better ways.
+export function useRerenderer(): [() => void, number] {
+ const [count, setCount] = useState(0);
+ const rerender = useCallback(() => setCount((count) => count + 1), []);
+ return [rerender, count];
+}