-
Notifications
You must be signed in to change notification settings - Fork 1
/
asynchronous.js
31 lines (25 loc) · 913 Bytes
/
asynchronous.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React, { useState } from "react";
export default () => {
const [count, setCount] = useState(0);
const increaseSync = () => setCount(prevCount => prevCount + 1);
const decreaseSync = () => setCount(prevCount => prevCount - 1);
const increaseAsync = () => {
setTimeout(() => {
increaseSync();
}, 1000);
};
const decreaseAsync = () => {
setTimeout(() => {
decreaseSync();
}, 1000);
};
return (
<div>
<p data-testid="count-displayer">{count}</p>
<button type="button" onClick={increaseSync}>Increase Sync</button>
<button type="button" onClick={decreaseSync}>Decrease Sync</button>
<button type="button" onClick={increaseAsync}>Increase Async</button>
<button type="button" onClick={decreaseAsync}>Decrease Async</button>
</div>
);
};