MCPcopy Create free account
hub / github.com/dailydotdev/apps / useObjectPurify

Function useObjectPurify

packages/shared/src/hooks/useDomPurify.ts:27–56  ·  view source on GitHub ↗
(
  obj: T,
  props: UseObjectPurifyOptionalProps<T> = {},
)

Source from the content-addressed store, hash-verified

25};
26
27export const useObjectPurify = <T extends PurifyObject>(
28 obj: T,
29 props: UseObjectPurifyOptionalProps<T> = {},
30): UseObjectPurify<T> => {
31 const { filters = [], defaultValue } = props;
32 const [purify, setPurify] = useState<DOMPurify>();
33
34 useEffect(() => {
35 setPurify(() => createDOMPurify(globalThis.window));
36 }, []);
37
38 const reduced = (keys: (keyof T)[]) =>
39 keys.reduce(
40 (result, key) => ({
41 ...result,
42 [key]: purify?.sanitize?.(obj[key]) ?? defaultValue?.[key] ?? '',
43 }),
44 { isReady: !!purify } as UseObjectPurify<T>,
45 );
46
47 return useMemo(() => {
48 if (filters.length === 0) {
49 return reduced(Object.keys(obj));
50 }
51
52 return reduced(filters);
53 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
54 // eslint-disable-next-line react-hooks/exhaustive-deps
55 }, [purify, obj, props]);
56};

Callers 3

NotificationItemLegacyFunction · 0.90
NotificationItemFunction · 0.90
InAppNotificationItemFunction · 0.90

Calls 1

reducedFunction · 0.85

Tested by

no test coverage detected