sandiiarov/use-popper

How to use the generated refs?

alexej-d opened this issue · 2 comments

What if one needs to reuse the generated refference's ref for another effect like this https://streamich.github.io/react-use/?path=/story/ui-useclickaway--docs?

As I see, refference.ref and popper.ref are just functions so it is not possible to access their current prop from outside to target the DOM element.

I am using mergeRefs helper

function mergeRefs(...refs) {
  return ref => {
    refs.forEach(resolvableRef => {
      if (typeof resolvableRef === 'function') {
        resolvableRef(ref);
      }

      if (resolvableRef) {
        resolvableRef.current = ref;
      }
    });
  };
}

https://codesandbox.io/s/0qjk4w5v0l

Great, didn't know this was possible, thanks!