Sometimes you run into a situation where you want to have
some logic that isn't associated with any rendered output
but starts/stops when a certain page is rendered. React can
handle this by rendering
null and using lifecycle events
to deal with listener attachment and cleanup.
The following code creates two components, one representing
the App and one to handle the logic.
App mounts or
KeydownListener once every second, forcing
componentWillUnmount to fire.
The output for the above is the following (which you can test in codesandbox.