question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to pass down the triggerRef

See original GitHub issue

Hi.

Is it possible to do something like this

type Props = {
  triggerRef: React.RefObject<HtmlElement>
}

funciton Tooltip(props: Props) {
  return <ToggleLayer triggerRef={props.triggerRef />
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
everweijcommented, Nov 27, 2019

Thanks for your explanation, I’ve created two examples with CodeSandbox, hopefully they will clarify some things. I agree the docs about useToggleLayer should cover more use-cases etc… will try to work on that the next couple of days.

Example A - ToggleLayer with Downshift’s useSelect (manages focus for you): https://codesandbox.io/s/select-menu-compound-8ds5e

Example B - useToggleLayer while ‘owning’ your own ref https://codesandbox.io/s/select-menu-usetogglelayer-xphuy

Note: If you just want access to the trigger-ref, you could also expose the trigger-ref to the outside as follows:

import mergeRefs from 'react-merge-refs';

const SelectMenu = React.forwardRef(function SelectMenu(props, forwardedRef) {
  return (
    <ToggleLayer
      // usual props...
    >
      {({ triggerRef}) => <div ref={mergeRefs(triggerRef, forwardedRef)} />}
    </ToggleLayer>
  );
});

// somewhere in your app...
function App() {
  const menuRef = React.useRef();

  React.useEffect(() => { /* do stuff with the ref... */}, [])

  return (
    <SelectMenu ref={menuRef} />
  )
}
0reactions
everweijcommented, Nov 28, 2019

Awesome! Like how you made your tooltip component. Thanks for showing, and glad I could help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

example for useOverlayTrigger is missing passing the ...
Expected Behavior ; Current Behavior ; Possible Solution ; Context ; Code Sample.
Read more >
Refs and the DOM - React
When a ref is passed to an element in render , a reference to the node becomes accessible at the current attribute of...
Read more >
React: why is that changing the current value of ref from ...
Normal render. myRef gets set to {current: 1} - Set up of refs only happens on initial render, so the line const myRef...
Read more >
EventListener - Triggers - Tekton
EventListener. EventListener is a Kubernetes custom resource that allows users a declarative way to process incoming HTTP based events with JSON payloads.
Read more >
Triggers - drone docs
12 13 14 15 16, trigger: ref: - refs/heads/master - refs/heads/** - refs/pull/*/head ... The branch trigger limits step execution based on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found