react-sticky icon indicating copy to clipboard operation
react-sticky copied to clipboard

Sticky element `ref` is overwriten

Open hepiyellow opened this issue 7 years ago • 2 comments

I'm submitting a ...

  • [x] bug report
  • [x] feature request
  • [ ] support request

If you're reporting a bug, please provide a minimal demonstration of the problem

What is the current behavior?

When rendering this Sticky element:

<Sticky>
  {
    ()=> <div ref={console.log('ref was called')}/>
  }
</Sticky>

The ref was called is not printed. Since here the ref prop is overwritten.

What is the expected or desired behavior?

I expect to be able to get a ref to my <div/>

Why do you want this? What use case do you have?

I might need something other than the supplied 'calculatedHeight`.

What is your environment?

  • Version: 6.0.3
  • Browser: Chrome

hepiyellow avatar Jul 21 '18 10:07 hepiyellow

Thanks for the report! Now that React provides a ref forwarding API this is definitely something we could provide. If you wanted to take a stab at it I'd be happy to merge a PR :)

vcarl avatar Jul 22 '18 20:07 vcarl

Oh this is an interesting bit from that post, however

When you start using forwardRef in a component library, you should treat it as a breaking change and release a new major version of your library.

That's a good point, if there are people relying on ref returning the instance of Sticky, changing this would break their application. I'm not sure the marginal improvement is worth a major version release at the moment.

vcarl avatar Jul 22 '18 20:07 vcarl