How to use the scheduler.unstable_runWithPriority function in scheduler

To help you get started, we’ve selected a few scheduler 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 jaredpalmer / formik / packages / formik / src / Formik.tsx View on Github external
(values: Values = state.values) => {
      return unstable_runWithPriority(LowPriority, () => {
        return runAllValidations(values)
        .then(combinedErrors => {
          if (!!isMounted.current) {
            dispatch({ type: 'SET_ERRORS', payload: combinedErrors });
          }
          return combinedErrors;
        })
        .catch(actualException => {
          if (process.env.NODE_ENV !== 'production') {
            // Users can throw during validate, however they have no way of handling their error on touch / blur. In low priority, we need to handle it
            console.warn(
              `Warning: An unhandled error was caught during low priority validation in `,
              actualException
            );
          }
        });
github facebook / react / packages / react-dom / src / events / ReactDOMEventReplaying.js View on Github external
): void {
  // TODO: This function shares a lot of logic with attemptToDispatchEvent.
  // Try to unify them. It's a bit tricky since it would require two return
  // values.
  let targetInst = getClosestInstanceFromNode(queuedTarget.target);
  if (targetInst !== null) {
    let nearestMounted = getNearestMountedFiber(targetInst);
    if (nearestMounted !== null) {
      const tag = nearestMounted.tag;
      if (tag === SuspenseComponent) {
        let instance = getSuspenseInstanceFromFiber(nearestMounted);
        if (instance !== null) {
          // We're blocked on hydrating this boundary.
          // Increase its priority.
          queuedTarget.blockedOn = instance;
          runWithPriority(queuedTarget.priority, () => {
            attemptHydrationAtCurrentPriority(nearestMounted);
          });
          return;
        }
      } else if (tag === HostRoot) {
        const root: FiberRoot = nearestMounted.stateNode;
        if (root.hydrate) {
          queuedTarget.blockedOn = getContainerFromFiber(nearestMounted);
          // We don't currently have a way to increase the priority of
          // a root other than sync.
          return;
        }
      }
    }
  }
  queuedTarget.blockedOn = null;
github facebook / react / packages / react-devtools-shared / src / devtools / views / Components / TreeContext.js View on Github external
(action: Action) => {
      // Run the first update at "user-blocking" priority in case dispatch is called from a non-React event.
      // In this case, the current (and "next") priorities would both be "normal",
      // and suspense would potentially block both updates.
      runWithPriority(UserBlockingPriority, () => dispatch(action));
      next(() => dispatch({type: 'UPDATE_INSPECTED_ELEMENT_ID'}));
    },
    [dispatch],
github react-spring / react-three-fiber / examples / demos / dev / Concurrent.js View on Github external
    if (change) setTimeout(() => run(low, () => set(Math.round(Math.random() * 0xffffff))), Math.random() * 1000)
  }, [change])
github bvaughn / react-window / src / SimpleList.js View on Github external
_prerenderOverscanRows = () => {
    this._prerenderOverscanRowsTimeoutID = null;

    runWithPriority(IdlePriority, () => {
      this.setState(prevState => {
        const {
          itemCount,
          maxNumPrerenderRows = DEFAULT_MAX_NUM_PRERENDER_ROWS,
        } = this.props;

        const [startIndex, stopIndex] = this._getVisibleIndicesForOffset(
          prevState.scrollTop
        );

        const numRowsPerViewport = stopIndex - startIndex;
        const numPrerenderRows = Math.min(
          numRowsPerViewport,
          maxNumPrerenderRows
        );
github facebook / react / packages / react-devtools-shell / src / app / PriorityLevels / index.js View on Github external
const startSequence = useCallback(() => {
    setDefaultPriority(true);
    runWithPriority(LowPriority, () => setLowPriority(true));
    runWithPriority(IdlePriority, () => setIdlePriority(true));
  }, []);
github philipp-spiess / scheduletron3000 / src / index.js View on Github external
function sendDeferredAnalyticsPing(value) {
  unstable_runWithPriority(unstable_LowPriority, function() {
    unstable_scheduleCallback(function() {
      sendAnalyticsPing(value);
    });
  });
}
github magoo-magoo / keyrier-json / src / components / query / QueryEditor.tsx View on Github external
(a: string) => {
            if (queryText !== a) {
                unstable_runWithPriority(unstable_IdlePriority, () => setQuery(a))
            }
        },
        [setQuery, queryText]
github facebook / react / packages / react-devtools-shell / src / app / PriorityLevels / index.js View on Github external
const startSequence = useCallback(() => {
    setDefaultPriority(true);
    runWithPriority(LowPriority, () => setLowPriority(true));
    runWithPriority(IdlePriority, () => setIdlePriority(true));
  }, []);