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

No clean way to force-update Sticky

Open karmeleon opened this issue 7 years ago • 7 comments

I've got a use case wherein I have a <StickyContainer/> on the right-hand side of the page that expands to the left when the user clicks a button, remaining sticky the whole time. Like this! Since this action doesn't fire any of the events that <StickyContainer/> listens for, its left hand side moves to the left but the child <Sticky/> and its contents don't until I scroll the page a tick. If I manually trigger an e.g. scroll event on the element I get from context.getParent(), it updates properly, but it feels hacky. I'd like a param passed from <Sticky/> to its child render function that I can invoke in order for the layout to update.

karmeleon avatar Mar 05 '18 22:03 karmeleon

Ah interesting! Good point, that does seem like a viable use-case. Do you have any specific API in mind? First thought would be an additional argument passed to the render callback, but I'm open to suggestions.

vcarl avatar Mar 06 '18 00:03 vcarl

Yeah I like the render argument idea! Easy to pass into whatever child components may want it, but equally easy to ignore if you don't need it.

karmeleon avatar Mar 06 '18 00:03 karmeleon

I want this too.

For now, as a workaround you can do window.dispatchEvent(new Event('scroll')) from anywhere, and it tricks the Sticky into re-rendering.

callumlocke avatar Mar 23 '18 14:03 callumlocke

really want it to be fixed asap, can't even wait for 6.1 I have a layout that has a transition in changing width That adds an extra challenge to the code, idk when to fire the scroll event too early the sticky component won't update, too late the animation just become ugly

marklai1998 avatar Feb 01 '19 10:02 marklai1998

Good thing there's a workaround then @marklai1998! I haven't had much time to dedicate to developing react-sticky, other projects have taken priority.

vcarl avatar Feb 01 '19 18:02 vcarl

@vcarl The scroll event workaround suggested by @callumlocke is fantastic. Perhaps that could be included in the README as a quick fix for cases where we need to trigger a sticky check?

Simon-Tang avatar Apr 05 '19 15:04 Simon-Tang

Good idea! I'm happy to merge a PR if you want to submit one @Simon-Tang :)

vcarl avatar Apr 05 '19 16:04 vcarl