コードタイピング · TypeScript
React Counter Hook
Minimal useState hook example.
難易度: 初級 · 9 行 · ライセンス: public-domain
import { useState } from 'react';
export function useCounter(initial = 0) {
const [count, setCount] = useState(initial);
const increment = () => setCount((n) => n + 1);
const decrement = () => setCount((n) => n - 1);
const reset = () => setCount(initial);
return { count, increment, decrement, reset };
}時間0:00
速度 (WPM)0.0
正確性100.0%
エラー0
ライブキーボード
次のキー: I | 最後のキー: -
進捗: 0.0%
半角
1
2
3
4
5
6
7
8
9
0
-
^
Q
W
E
R
T
Y
U
I
O
P
@
[
A
S
D
F
G
H
J
K
L
;
:
Z
X
C
V
B
N
M
,
.
/
スペース
ランキング
まだ結果がありません。