How to use the react-tracked.getUntrackedObject function in react-tracked

To help you get started, we’ve selected a few react-tracked examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dai-shi / react-tracked / examples / 10_untracked / src / store.ts View on Github external
const untrackDeep = (obj: T) => {
  if (typeof obj !== 'object' || obj === null) return obj;
  const untrackedObj = getUntrackedObject(obj);
  if (untrackedObj !== null) return untrackedObj;
  const newObj = {} as T;
  let modified = false;
  Object.entries(obj).forEach(([k, v]) => {
    const vv = untrackDeep(v);
    if (vv !== null) {
      newObj[k as keyof T] = vv;
      modified = true;
    } else {
      newObj[k as keyof T] = v;
    }
  });
  return modified ? newObj : obj;
};

react-tracked

State usage tracking with Proxies. Optimize re-renders for useState/useReducer, React Redux, Zustand and others.

MIT
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis