Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sbussard
Last active May 16, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbussard/b2d4ef97efcb59b8dc65084df90eb4b3 to your computer and use it in GitHub Desktop.
Save sbussard/b2d4ef97efcb59b8dc65084df90eb4b3 to your computer and use it in GitHub Desktop.
import React, { useState } from "react";
let ChildComponent = ({ setRef }) => <div ref={setRef}>{/* content */}</div>;
let ParentComponent = () => {
let [ref, setRef] = useState();
useEffect(() => {
if (ref) {
// whatever you want to use ref for
}
}, [ref]);
return <ChildComponent setRef={setRef} />;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment