Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用styled-componentsnpm 包并在组件上设置了一个事件,如下所示:
styled-components
<MyStyledComponent onKeyPress={e => doSomething(e)} >
如何捕获密钥代码?
styled-components 不会以任何方式改变 React 合成事件对象,因此您需要检查event.charCode.event.keyCode
event.charCode
event.keyCode