Suppose that we are displaying a large number of data, such as 10thousands of data, there is often a delay in puuting next value to the input field.
In this case, when we enter a value, the screen displays filtered data.
But then, a problem that occurs is the delay in displaying the next action such as input next value to input field due to handling too much data.
・src/Example.js
import { useState } from "react"; const generateDummyItem = (num) => { return new Array(num).fill(null).map((item, index) => `item ${index}`); }; const dummyItems = generateDummyItem(10000); const Example = () => { const [filterVal, setFilterVal] = useState(""); const changeHandler = (e) => { setFilterVal(e.target.value); }; return ( {isPending &&Loading...}
const changeHandler = (e) => { startTransition(() => { setFilterVal(e.target.value); }) };
The startTransition makes a function delay to be executed within it.
Thanks to this feature, we can easily move on to the next value in the input field.
・Before input
・After input
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3