Answer the question
In order to leave comments, you need to log in
Are use effect and componentDidMount the same thing?
use effect
in React 16 has the same/similar functionality and purpose as componentDidMount
in React 15?
Answer the question
In order to leave comments, you need to log in
useEffect is wider
componentDidMount() {
window.addEventListener('mousemove', () => {})
}
componentWillUnmount() {
window.removeEventListener('mousemove', () => {})
}
useEffect(() => {
window.addEventListener('mousemove', () => {});
// returned function will be called on component unmount
return () => {
window.removeEventListener('mousemove', () => {})
}
}, [])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question