Epic React V2

Transitions

Adding a transition to the checkbox state change with useTransition() from react.

const [isPending, startTransition] = useTransition(false)

const [isPending, startTransition] = useTransition();

<input
  onChange={(e) => {
    startTransition(() => {
      setShowGlobe(e.currentTarget.checked);
    });
  }}
/>

Avoiding flash of pending state
useSpinDelay delays displaying the pending state to prevent unnecessary flickering when a transition completes quickly.
The default delay is 200ms, but you can customise it by passing an options object with a delay property to the hook.

const isPending = useSpinDelay(isTransitionPending, { delay: 200 });

To test it on console tab network choose Fast 4G, clear cache, and click the checkbox to show the globe.