Looks like componentWillMount is being deprecated.
I'm using it to check for keydown events (and componentWillUnmount for removeing the event):
componentWillMount() {
document.addEventListener("keydown", this.handleKeyDown);
}
componentWillUnmount() {
document.removeEventListener("keydown", this.handleKeyDown);
}
In the blog example they move it to componentDidMount. Should I just move it there too?
Edit: fixed the typo, I was talking about componentWillMount not componentWillUnmount.
From the react documentation: componentDidMount() is invoked immediately after a component is mounted. Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.
This method is a good place to set up any subscriptions. If you do that, don’t forget to unsubscribe in componentWillUnmount().
Scott Cox
JavaScript Developer
I don't think
componentWillUnmount()is getting deprecated. You refer tocomponentWillMount()later so I think you might have made a typo there :)Currently I add event listeners in
componentDidMount()and remove them incomponentWillUnmount(). It's worked really well for me so far.