/** * title: 基本用法 * desc: 支持键盘事件中的 key 和 keyCode,请按 ArrowUp 或 ArrowDown 键进行演示。 */ import React, { useState, useRef } from 'react'; import useKeyPress from "../../useKeyPress"; // 支持使用别名,更多内容请[查看备注](#备注)。 function Demo2(): JSX.Element { const [counter, setCounter] = useState(0); useKeyPress('left', () => { setCounter((s) => s - 1); }); useKeyPress('right', () => { setCounter((s) => s + 1); }); return (
Try pressing the following:
Try pressing the following:
Input and pressing enter: {text}
Input and pressing enter: {textRef}
Input after enter change: {textSync}
Try pressing the following:
demo2
demo3
demo4
demo5