Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Scroll Reset Component is not functioning, when switching to different routes #95

Closed
idontknowjs opened this issue Sep 25, 2020 · 11 comments · Fixed by #106 or #164
Closed

Scroll Reset Component is not functioning, when switching to different routes #95

idontknowjs opened this issue Sep 25, 2020 · 11 comments · Fixed by #106 or #164
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@idontknowjs
Copy link
Contributor

While switching to a different route
The scroll postion is expected to move to top ( window.scrollTo(0, 0) )
But it remains fixed and does not work the way it was expected in the function

@KeenWarrior KeenWarrior added bug Something isn't working help wanted Extra attention is needed labels Sep 25, 2020
@idontknowjs
Copy link
Contributor Author

The possible reason I could find out is that location.state is undefined, it should be either null but not undefined
image

@KeenWarrior
Copy link
Contributor

You can also take a look at https://stackoverflow.com/a/39345165

@idontknowjs
Copy link
Contributor Author

Hi, so yes I already tried using useEffect and the clean up function, wrapping with withRouter
As below

import { useEffect } from "react";
import { withRouter } from "react-router-dom";

function ScrollReset({ history }) {
  useEffect(() => {
    const unlisten = history.listen(() => {
      window.scrollTo(0, 0);
    });
    return () => {
      unlisten();
    };
  }, [history]);

  return null;
}

export default withRouter(ScrollReset);

But it was also not working as it was expected.

Tested the existing ScrollReset Component of the directory and the above new component in another project of mine.
Both worked over there, but not functioning here
Was unable to find the actual reason behind this

@KeenWarrior
Copy link
Contributor

This seems like a complication. Are you feeling comfortable working on it? Or need someone associated with you on it?

@idontknowjs
Copy link
Contributor Author

This seems like a complication. Are you feeling comfortable working on it? Or need someone associated with you on it?

Yes, it would be better

@idontknowjs
Copy link
Contributor Author

If anyone else is interested, can take this issue. I am currently not able to debug it

@ArunTeltia
Copy link
Contributor

I am working on this

@ArunTeltia
Copy link
Contributor

@Abhishek-kumar09
Copy link
Contributor

Not yet.

@ArunTeltia
Copy link
Contributor

OKay i am trying it then

@ArunTeltia
Copy link
Contributor

So I tried a lot of things but nothing works, The problem with this is the page is in the form of overflow:scroll now when we are trying to make it to ScrollTop the page render this component but the problem here is The page is already on top (because of the TopBar) , We can resolve this issue but we need to make the overflow to be visible
Now the problem with this we have to give margin-bottom on the topbar and the scrollbar will appear at the topbar as well

I am not able to deduct any other solution to this, can you help me @Abhishek-kumar09

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
4 participants