给出一个定义如下的组件:
export default class KeyboardShortcut extends React.Component {
componentDidMount() {
window.addEventListener('keydown', e => this.handleKeyDown(e));
}
componentWillUnmount() {
window.removeEventListener('keydown', this.handleKeyDown);
}
handleKeyDown(e) {
if (e.key === 'c') {
// what goes here?
}
}
render() {
return this.props.children
}
}
当handleKeyDown
中处理的键盘事件类型(即,按字母c的事件)发生时,如何在子节点上生成或触发点击事件?