MCPcopy Create free account
hub / github.com/msgbyte/tailchat / useShallowObject

Function useShallowObject

client/shared/hooks/useShallowObject.ts:7–17  ·  view source on GitHub ↗
(object: T)

Source from the content-addressed store, hash-verified

5 * 对输入对象增加一层浅比较, 如果对象浅比较结果一致则返回原对象(防止更新)
6 */
7export function useShallowObject<T>(object: T): T {
8 const [state, setState] = useState<T>(object);
9
10 useLayoutEffect(() => {
11 if (!shallowEqual(state, object)) {
12 setState(object);
13 }
14 }, [object]);
15
16 return state;
17}

Callers 1

context.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected