Last active
May 16, 2019 19:27
-
-
Save sbussard/b2d4ef97efcb59b8dc65084df90eb4b3 to your computer and use it in GitHub Desktop.
Revisions
-
sbussard revised this gist
May 16, 2019 . 1 changed file with 3 additions and 2 deletions.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 @@ -1,5 +1,6 @@ import React, { useState } from "react"; let ChildComponent = ({ setRef }) => <div ref={setRef}>{/* content */}</div>; let ParentComponent = () => { let [ref, setRef] = useState(); @@ -10,5 +11,5 @@ let ParentComponent = () => { } }, [ref]); return <ChildComponent setRef={setRef} />; }; -
sbussard created this gist
May 16, 2019 .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,14 @@ import React, { useState } from "react"; import ChildComponent from "../etc/somewhere"; let ParentComponent = () => { let [ref, setRef] = useState(); useEffect(() => { if (ref) { // whatever you want to use ref for } }, [ref]); return <ChildComponent ref={setRef} />; };