Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-start-transition

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-start-transition

React 18 startTransition polyfill

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-start-transition

React 18 startTransition polyfill

With the upcoming startTransition primitive coming to React 18, I decided to create a lil polyfill to help developers transition to the new API and get some perf improvements already.

This lib won't have the same perf impact as the native startTransition will since it doesn't have access to React internals (more info here) but it will use what's best available and only run the tasks when the browser is not busy doing other more critical stuff.

A combination of isInputPending and requestIdleCallback browser API's will be used for that.

Install

$ yarn add react-start-transition

Usage

import * as React from "react";
import { useState } from "react";
import { useTransition } from 'react-start-transition'

const App = () => {
  const [isPending, startTransition] = useTransition();
  const [inputValue, setInputValue] = useState(5);
  const onChange = (value: number) => {
    startTransition(() => setInputValue(value));
  };
  
  return (
    <div>
      <Slider defaultValue={inputValue} onChange={onChange} />
      <div>{isPending && 'loading...'}</div>
      <div>{inputValue}</div>
    </div>
  );
};


isPending

Notice that when you use the isPending from

const [isPending, startTransition] = useTransition();

it will be coupled to the task that you run within the startTransition and will done whenever that task get ran by the internal scheduler.

Keywords

FAQs

Package last updated on 04 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc