Skip to content

Instantly share code, notes, and snippets.

@farism
Last active June 10, 2019 20:12
Show Gist options
  • Save farism/444e07de81e9dfc08ac291452bb80d60 to your computer and use it in GitHub Desktop.
Save farism/444e07de81e9dfc08ac291452bb80d60 to your computer and use it in GitHub Desktop.
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