import React, { useMemo } from "react"; import { useSelectionContext } from "../useSelection"; type AddressHighlighterProps = React.PropsWithChildren<{ address: string; }>; const AddressHighlighter: React.FC = ({ address, children, }) => { const [selection, setSelection] = useSelectionContext(); const [select, deselect] = useMemo(() => { const _select = () => { setSelection({ type: "address", content: address }); }; const _deselect = () => { setSelection(null); }; return [_select, _deselect]; }, [setSelection, address]); return ( {children} ); }; type _AddressHighlighterImplProps = { selected: boolean; select: () => void; deselect: () => void; }; const AddressHighlighterImpl: React.FC<_AddressHighlighterImplProps> = React.memo(({ selected, select, deselect, children }) => (
{children}
)); export default AddressHighlighter;