component will mount in react hooks code example
Example 1: replace componentwillmount with hooks
useEffect(() => {
})
useEffect(() => {
window.addEventListener('mousemove', () => {});
return () => {
window.removeEventListener('mousemove', () => {})
}
}, [])
Example 2: component did mount in hooks
For componentDidMount
useEffect(() => {
}, []);
For componentDidUpdate
useEffect(() => {
}, [yourDependency]);
For componentWillUnmount
useEffect(() => {
return () => {
}
}, [yourDependency]);
Example 3: componentwillunmount hooks
useEffect(() => {
window.addEventListener('mousemove', () => {});
return () => {
window.removeEventListener('mousemove', () => {})
}
}, [])
Example 4: react hook will mount
const useComponentWillMount = (func: (params?: any) => any) => useMemo(func, []);
Example 5: componentdidmount in hooks
useEffect(() => {
}, []);