Skip to content

Commit daf25bf

Browse files
committed
do not use defer in sync mode
1 parent 07cf789 commit daf25bf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/components/concurrent/Concurrent2.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { unstable_scheduleCallback } from 'scheduler';
33

44
const LargeList = ({ remainder }) => {
55
return <ul>
6-
{[...Array(2000).keys()].map((n) => {
6+
{[...Array(2000).keys()].map(n => {
77
return (remainder === n % 2) && <li key={n}>{n}</li>;
88
})}
99
</ul>;
@@ -13,6 +13,8 @@ function Concurrent2() {
1313
const [query, setQuery] = useState('');
1414
const [remainder, setRemainder] = useState(0);
1515

16+
const mode = window.localStorage.getItem('mode');
17+
1618
return <div>
1719
<input
1820
type="text"
@@ -21,9 +23,14 @@ function Concurrent2() {
2123
const value = e.target.value;
2224
const remainder = value.length % 2;
2325
setQuery(value);
24-
unstable_scheduleCallback(() => {
26+
27+
if (mode === 'concurrent') {
28+
unstable_scheduleCallback(() => {
29+
setRemainder(remainder);
30+
});
31+
} else {
2532
setRemainder(remainder);
26-
})
33+
}
2734
}}
2835
/>{' '}{query.length}
2936
<LargeList remainder={remainder}/>

0 commit comments

Comments
 (0)