diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-05-23 23:45:12 -0400 | 
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-05-23 23:45:12 -0400 | 
| commit | 27ecedb02ef79ce53bf533e016b00462c44541be (patch) | |
| tree | 402305113b6f04c3e3b3563b68d32de5ff1c69c8 /extension/react-app/src/redux/hooks.ts | |
| download | sncontinue-27ecedb02ef79ce53bf533e016b00462c44541be.tar.gz sncontinue-27ecedb02ef79ce53bf533e016b00462c44541be.tar.bz2 sncontinue-27ecedb02ef79ce53bf533e016b00462c44541be.zip | |
copying from old repo
Diffstat (limited to 'extension/react-app/src/redux/hooks.ts')
| -rw-r--r-- | extension/react-app/src/redux/hooks.ts | 21 | 
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]; +} | 
