captivationsoftware / react-sticky

<Sticky /> component for awesome React apps
MIT License
2.64k stars 385 forks source link

I can't use a single component to render, need to wrap it in additional one #192

Closed smolak closed 6 years ago

smolak commented 7 years ago

Hi

When I try to do this:

<Sticky>
    {() => {
        return <SomeComponent some={prop} />;
    }}         
</Sticky>

It will fail with Sticky.js:61 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null.

But when I do this:

<Sticky>
    {() => {
        return <div><SomeComponent some={prop} /></div>;
    }}         
</Sticky>

It works. It works also when you render a component without props (can have children though):

<Sticky>
    {() => {
        return <div>Something here</div>;
    }}         
</Sticky>

It should work forall cases, in my opinion.

dbarbalato commented 7 years ago

Are you using functional components by any chance? This version relies on using a component's ref, and purely functional components do not support refs.

If not, sounds like a legit bug

vcarl commented 6 years ago

Closing due to lack of response. Happy to reopen if the problem isn't because of function components.