Created
January 12, 2023 15:57
-
-
Save GuilhemBarboux/4330e8c1641d657ea294bbf7bf8cd680 to your computer and use it in GitHub Desktop.
Revisions
-
GuilhemBarboux created this gist
Jan 12, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ import React, { FunctionComponent, useEffect, useLayoutEffect } from 'react'; interface OwnChildProps {} type ChildProps = OwnChildProps; const Child: FunctionComponent<ChildProps> = props => { useEffect(() => { console.log('Child useEffect'); return () => { console.log('Child release useEffect'); }; }, []); useLayoutEffect(() => { console.log('Child useLayoutEffect'); return () => { console.log('Child release useLayoutEffect'); }; }, []); console.log('Child render function'); return; }; interface OwnParentProps {} type ParentProps = OwnParentProps; const Parent: FunctionComponent<ParentProps> = props => { const [active, setActive] = useState(false); useEffect(() => { console.log('Parent useEffect'); setActive(true); return () => { console.log('Parent release useEffect'); }; }, [active, setActive]); useLayoutEffect(() => { console.log('Parent useLayoutEffect'); return () => { console.log('Parent release useLayoutEffect'); }; }, []); console.log('Parent render function'); return <Child />; }; export default Parent;