Skip to content

Commit 1e0b983

Browse files
use concurrent features
1 parent df3908c commit 1e0b983

File tree

1 file changed

+7
-5
lines changed
  • frameworks/keyed/react-hooks/src

1 file changed

+7
-5
lines changed

frameworks/keyed/react-hooks/src/main.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useReducer } from 'react';
1+
import { memo, useCallback, useReducer, useTransition } from 'react';
22
import { createRoot } from 'react-dom/client';
33

44
const random = (max) => Math.round(Math.random() * 1000) % max;
@@ -107,14 +107,16 @@ const Jumbotron = memo(({ dispatch }) => (
107107

108108
const Main = () => {
109109
const [{ data, selected }, dispatch] = useReducer(listReducer, initialState);
110+
const [, startTransition] = useTransition();
111+
const transitionedDispatch = useCallback((...args) => startTransition(() => dispatch(...args)), []);
110112

111113
return (<div className="container">
112-
<Jumbotron dispatch={dispatch} />
114+
<Jumbotron dispatch={transitionedDispatch} />
113115
<table className="table table-hover table-striped test-data">
114116
<tbody>
115-
{data.map(item => (
116-
<Row key={item.id} item={item} selected={selected === item.id} dispatch={dispatch} />
117-
))}
117+
{data.map(item => (
118+
<Row key={item.id} item={item} selected={selected === item.id} dispatch={transitionedDispatch} />
119+
))}
118120
</tbody>
119121
</table>
120122
<span className="preloadicon glyphicon glyphicon-remove" aria-hidden="true" />

0 commit comments

Comments
 (0)