DEV Community

AKSH DESAI
AKSH DESAI

Posted on

1

useTransition - Web Dev Simplified

App.js Code

import { useState, useTransition } from 'react'


export default function App() {
    const [isPending, startTransaction] = useTransition();

    const [input, setInput] = useState("");
    const [list, setList] = useState([]);

    const LIST_SIZE = 20000;

    function handleChange(e) {
        setInput(e.target.value);

        startTransaction(() => {
            const l = [];
            for (let i = 0; i < LIST_SIZE; i++) {
                l.push(e.target.value);
            };
            setList(l);
        })
    }

    return (
        <>
            <input type="text" value={input} onChange={handleChange} />

            {isPending ? 'LOADING...' : list.map((item, index) => {
                return <span key={index}> {item} </span>
            })}
        </>
    )
}
Enter fullscreen mode Exit fullscreen mode

Output

Output

Output

Thank You.
You can follow us on:
Youtube
Instagram

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs