otterscan/src/useSelection.ts

32 lines
621 B
TypeScript
Raw Normal View History

2021-10-22 18:50:31 +00:00
import {
Dispatch,
SetStateAction,
createContext,
useState,
useContext,
} from "react";
2021-07-14 06:52:31 +00:00
export type SelectionType = "address" | "value" | "functionSig";
2021-07-14 06:52:31 +00:00
export type Selection = {
type: SelectionType;
2021-07-14 06:52:31 +00:00
content: string;
};
export type OptionalSelection = Selection | null;
2021-10-22 18:50:31 +00:00
2021-07-14 06:52:31 +00:00
export const useSelection = (): [
2021-10-22 18:50:31 +00:00
OptionalSelection,
Dispatch<SetStateAction<OptionalSelection>>
2021-07-14 06:52:31 +00:00
] => {
2021-10-22 18:50:31 +00:00
return useState<OptionalSelection>(null);
2021-07-14 06:52:31 +00:00
};
2021-10-22 18:50:31 +00:00
export const SelectionContext = createContext<ReturnType<typeof useSelection>>(
null!
);
2021-07-14 06:52:31 +00:00
export const useSelectionContext = () => {
2021-10-22 18:50:31 +00:00
return useContext(SelectionContext);
2021-07-14 06:52:31 +00:00
};