John O'Donnell
John O'Donnell

Reputation: 159

React Keyboard event listener on window

What is the best way to attach an event listener on a div/window that listens for keypress in React. I know the synthetic keyboard events that you can attach to form fields, like onKeyDown etc. Is there any down falls to attaching just vanilla JS eventListeners on window in ComponentDidMount?

Upvotes: 0

Views: 472

Answers (1)

Piyush.kapoor
Piyush.kapoor

Reputation: 6803

As long as you dont manipulate the Dom outside react render it is safe to attach events on window

Upvotes: 1

Related Questions