summaryrefslogtreecommitdiff
path: root/extension/react-app/src/redux/hooks.ts
diff options
context:
space:
mode:
authorNate Sesti <sestinj@gmail.com>2023-05-23 23:45:12 -0400
committerNate Sesti <sestinj@gmail.com>2023-05-23 23:45:12 -0400
commitf53768612b1e2268697b5444e502032ef9f3fb3c (patch)
tree4ed49b73e6bd3c2f8fceffa9643973033f87af95 /extension/react-app/src/redux/hooks.ts
downloadsncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.tar.gz
sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.tar.bz2
sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.zip
copying from old repo
Diffstat (limited to 'extension/react-app/src/redux/hooks.ts')
-rw-r--r--extension/react-app/src/redux/hooks.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/extension/react-app/src/redux/hooks.ts b/extension/react-app/src/redux/hooks.ts
new file mode 100644
index 00000000..a6aef869
--- /dev/null
+++ b/extension/react-app/src/redux/hooks.ts
@@ -0,0 +1,21 @@
+import { useCallback } from "react";
+import { useDispatch, useSelector } from "react-redux";
+import { RootStore } from "./store";
+import { selectDebugContextValue } from "./selectors/debugContextSelectors";
+import { updateValue } from "./slices/debugContexSlice";
+import { SerializedDebugContext } from "../../../src/client";
+
+export function useDebugContextValue(
+ key: keyof SerializedDebugContext,
+ defaultValue: any
+): [any, (value: any) => void] {
+ const dispatch = useDispatch();
+ const state =
+ useSelector((state: RootStore) => selectDebugContextValue(state, key)) ||
+ defaultValue;
+ const boundAction = useCallback(
+ (value: any) => dispatch(updateValue({ key, value })),
+ [dispatch, key]
+ );
+ return [state, boundAction];
+}