diff --git a/src/components/AddressHighlighter.tsx b/src/components/AddressHighlighter.tsx index 1b7df0d..e8078d6 100644 --- a/src/components/AddressHighlighter.tsx +++ b/src/components/AddressHighlighter.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useMemo } from "react"; import { useSelectionContext } from "../useSelection"; type AddressHighlighterProps = React.PropsWithChildren<{ @@ -10,12 +10,15 @@ const AddressHighlighter: React.FC = ({ children, }) => { const [selection, setSelection] = useSelectionContext(); - const select = () => { - setSelection({ type: "address", content: address }); - }; - const deselect = () => { - setSelection(null); - }; + const [select, deselect] = useMemo(() => { + const _select = () => { + setSelection({ type: "address", content: address }); + }; + const _deselect = () => { + setSelection(null); + }; + return [_select, _deselect]; + }, [setSelection, address]); return (
> + OptionalSelection, + Dispatch> ] => { - const [selection, setSelection] = useState(null); - return [selection, setSelection]; + return useState(null); }; -export const SelectionContext = React.createContext< - ReturnType ->(null!); +export const SelectionContext = createContext>( + null! +); export const useSelectionContext = () => { - const ctx = useContext(SelectionContext); - return ctx; + return useContext(SelectionContext); };