The game would be improved if the keyboard could be used. Currently you must click the buttons at the bottom of the grid.
Goal: add listeners for keyboard events.
left arrow: move left
right arrow: move right
up/down: arrow rotate
space bar: move down.
The event listeners will need to issue actions to the Redux dispatcher. The existing actions should work. Where you add the listeners could use some thought. Two places stand out.
The Controls component. This might be nice since the keyboard actions will be in the same place as the button actions and they do the same things. The actions are here and this component is connected to Redux already.
The second option is to add the keyboard actions to the App component. You'll need to connect this to Redux and import the actions.
In either case you should probably add listeners for keyboard events in componentDidMount and remove them in componentWillUnmount.
The game would be improved if the keyboard could be used. Currently you must click the buttons at the bottom of the grid.
Goal: add listeners for keyboard events.
The event listeners will need to issue actions to the Redux dispatcher. The existing actions should work. Where you add the listeners could use some thought. Two places stand out.
The Controls component. This might be nice since the keyboard actions will be in the same place as the button actions and they do the same things. The actions are here and this component is connected to Redux already.
The second option is to add the keyboard actions to the App component. You'll need to connect this to Redux and import the actions.
In either case you should probably add listeners for keyboard events in
componentDidMount
and remove them incomponentWillUnmount
.Here is some info on keyboard events in react:
Possible issues: