Last active
June 10, 2019 20:12
-
-
Save farism/444e07de81e9dfc08ac291452bb80d60 to your computer and use it in GitHub Desktop.
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 characters
const ComponentA = (props, ref) => { | |
<div ref={ref}>a</div> | |
} | |
const ComponentB = (props, ref) => { | |
<ComponentA ref={ref} /> | |
} | |
const ComponentC = () => { | |
const bRef = React.createRef() | |
const handler = (e) => { | |
// do something | |
} | |
onKeyDown({ | |
handler, | |
scope: bRef | |
}) | |
<> | |
<ComponentB ref={bRef} /> // passing ref deep down | |
<div onKeyDown={handler}) /> // already has context, just use onKeyDown | |
</> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment