Skip to content

Instantly share code, notes, and snippets.

@wlizama
Created June 4, 2020 23:26
Show Gist options
  • Save wlizama/9c8f80187513e9b3aa6cc79f340de11c to your computer and use it in GitHub Desktop.
Save wlizama/9c8f80187513e9b3aa6cc79f340de11c to your computer and use it in GitHub Desktop.
hook alternative to ComponentWillMount lifecycle method
import React, { useRef, useEffect } from 'react';
const useComponentWillMount = func => {
const willMount = useRef(true);
useEffect(() => {
willMount.current = false;
}, []);
if (willMount.current) { func(); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment