Last active
November 9, 2020 20:46
-
-
Save kellenmace/156efd21389050870313d0cf9356be70 to your computer and use it in GitHub Desktop.
React component that returns true once the component/hook using it has mounted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from "react" | |
/** | |
* @return {boolean} Whether the component has mounted. | |
*/ | |
function useHasMounted() { | |
const [hasMounted, setHasMounted] = useState(false) | |
useEffect(() => { | |
setHasMounted(true) | |
}, []) | |
return hasMounted | |
} | |
export default useHasMounted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment