Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

replace componentwillmount with hooks

useEffect(() => {
	//will be called on every load
})

useEffect(() => {
	//will be called on component mount
  window.addEventListener('mousemove', () => {});

  // returned function will be called on component unmount 
  return () => {
    window.removeEventListener('mousemove', () => {})
  }
}, []) // <---- empty array at end will cause to only run on first load
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #replace #componentwillmount #hooks
ADD COMMENT
Topic
Name
3+7 =