diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index c2d043ad1..4b7aafce4 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -563,6 +563,22 @@ "hash": "82ef558fad661a522f5e897014b3898ad56ab6603a342c477f09edaa6281a0c9" } }, + { + "id": "useComponentWillUnmount", + "type": "snippetListing", + "title": "useComponentWillUnmount", + "attributes": { + "text": "A hook that executes a callback immediately before a component is unmounted and destroyed.\n\n- Use `React.useEffect()` with an empty array as the second argument and return the provided callback to be executed only once before cleanup.\n\n", + "tags": [ + "hooks", + "effect", + "beginner" + ] + }, + "meta": { + "hash": "dd2769c603f226996de8baf90af511fc788543dcb194a3b600f83fd2916699a6" + } + }, { "id": "useFetch", "type": "snippetListing", diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 44be288f5..f2b2678df 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -903,6 +903,32 @@ "authorCount": 2 } }, + { + "id": "useComponentWillUnmount", + "title": "useComponentWillUnmount", + "type": "snippet", + "attributes": { + "fileName": "useComponentWillUnmount.md", + "text": "A hook that executes a callback immediately before a component is unmounted and destroyed.\n\n- Use `React.useEffect()` with an empty array as the second argument and return the provided callback to be executed only once before cleanup.\n\n", + "codeBlocks": { + "style": "", + "code": "const useComponentWillUnmount = onUnmountHandler => {\n React.useEffect(() => () => {\n onUnmountHandler()\n }, []);\n}", + "example": "const Unmounter = () => {\n useComponentWillUnmount(() => console.log('Component will unmount'));\n\n return
Check the console!
;\n}\n\nReactDOM.render(, document.getElementById('root'));" + }, + "tags": [ + "hooks", + "effect", + "beginner" + ] + }, + "meta": { + "hash": "dd2769c603f226996de8baf90af511fc788543dcb194a3b600f83fd2916699a6", + "firstSeen": "1578060056", + "lastUpdated": "1578060056", + "updateCount": 2, + "authorCount": 2 + } + }, { "id": "useFetch", "title": "useFetch",