И
useAtom(itemsAtom, items => { type: items[id]?.type, second: items[id]?.second }, [id]);
хотя так тоже будет новый объект же
Size: a a a
И
a
useAtom(itemsAtom, items => { type: items[id]?.type, second: items[id]?.second }, [id]);
a
И
a
И
И
И
И
a
И
useAtom(itemsAtom, (items) => useMemo(items[selected], isEqual), [selected]);
типа того?a
useAtom(itemsAtom, items => { type: items[id]?.type, second: items[id]?.second }, [id]);
function createShallowMemoSelector(selector) {
let cacheI;
let cacheIKeys;
let cacheO;
return (input) => {
if (!cacheI) {
cacheIKeys = Object.keys((cacheI = input));
return (cacheO = selector(input));
}
const iKeys = Object.keys(input);
if (
cacheIKeys.length === iKeys.length &&
iKeys.every((k) => Object.is(input[k], cacheI[k]))
) {
return cacheO;
}
cacheI = input;
cacheIKeys = iKeys;
return (cacheO = selector(input));
};
}
И
createShallowMemoSelector
a
const memoComputed = useCallback(createShallowMemoSelector(v => v))
const {a, b} = useAtom(listAtom, items => memoComputed({a: items[id].a, b: items[id].b}), [id])
И
const memoComputed = useCallback(createShallowMemoSelector(v => v))
const {a, b} = useAtom(listAtom, items => memoComputed({a: items[id].a, b: items[id].b}), [id])
createShallowMemoSelector
a
createShallowMemoSelector
И
И
И
a
function createShallowMemoSelector(selector) {
let cacheI;
let cacheIKeys;
let cacheO;
return (input) => {
if (!cacheI) {
cacheIKeys = Object.keys((cacheI = input));
return (cacheO = selector(input));
}
const iKeys = Object.keys(input);
if (
cacheIKeys.length === iKeys.length &&
iKeys.every((k) => Object.is(input[k], cacheI[k]))
) {
return cacheO;
}
cacheI = input;
cacheIKeys = iKeys;
return (cacheO = selector(input));
};
}