Created
September 6, 2017 02:27
-
-
Save rob-mcgrail/38186216e64a1fd74a6657bbd156688b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { withRouter } from 'react-router-native'; | |
const HistoryListener = class extends Component { | |
static propTypes = { | |
history: PropTypes.object.isRequired, | |
callback: PropTypes.func.isRequired, | |
delay: PropTypes.number | |
} | |
static defaultProps = { | |
delay: 0 | |
} | |
constructor(props) { | |
super(props); | |
const callback = () => { | |
setTimeout(() => { | |
props.callback(); | |
}, props.delay); | |
}; | |
this.state = { | |
unlisten: props.history.listen(callback) | |
}; | |
} | |
componentWillUnmount() { | |
this.state.unlisten(); | |
} | |
render() { | |
return null; | |
} | |
}; | |
export default withRouter(HistoryListener); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment