Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No clean way to force-update Sticky #231

Open
karmeleon opened this issue Mar 5, 2018 · 7 comments
Open

No clean way to force-update Sticky #231

karmeleon opened this issue Mar 5, 2018 · 7 comments

Comments

@karmeleon
Copy link

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.

@vcarl
Copy link
Contributor

vcarl commented Mar 6, 2018

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.

@karmeleon
Copy link
Author

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.

@callumlocke
Copy link

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.

@vcarl vcarl added the 6.1 label Jun 29, 2018
@marklai1998
Copy link

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

@vcarl
Copy link
Contributor

vcarl commented Feb 1, 2019

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.

@Simon-Tang
Copy link

@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?

@vcarl
Copy link
Contributor

vcarl commented Apr 5, 2019

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

Simon-Tang added a commit to Simon-Tang/react-sticky that referenced this issue Apr 8, 2019
Adds workaround mentioned in captivationsoftware#231 for triggering layout check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants