Answers for "react hooks will mount"

2

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
Posted by: Guest on July-16-2020
0

react hook will mount

const useComponentWillMount = (func: (params?: any) => any) => useMemo(func, []);
Posted by: Guest on May-18-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language