Skip to content

Instantly share code, notes, and snippets.

@sbussard sbussard/exampleRef.js
Last active May 16, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.