I am in the process of developing a custom ScrollToTop
component using MUI's useScrollTrigger
hook. More information can be found at this link
Feel free to check out the sample code here: https://codesandbox.io/s/stackoverlow-mui-usescrolltrigger-er9z4y
Challenges
- The
ScrollTop
component does not show up after scrolling, even when reaching the bottom of the page.
Please refer to the screenshot below.
The ScrollToTop
component should appear in the area I have marked.
When analyzing the code, it appears that the trigger
value from the useScrollTrigger
hook is consistently returning a value of false
, instead of changing to true
upon scrolling.
https://i.sstatic.net/22YLg.png
- If we were to remove the comment tags from the
ScrollToTop
component, it would become visible. However, clicking on the component does not return the screen to the top of the page as expected.
Refer to the screenshot below. https://i.sstatic.net/ip94x.png
Steps To Reproduce
For the first problem:
- Access the demo using the codesandbox link provided above.
- Scroll down to the bottom of the page.
Regarding the second issue:
- Also access the demo using the codesandbox link provided above.
- Uncomment the
ScrollToTop
component. - Scroll down to the bottom of the page.
- Click on the
ScrollToTop
component.
Expected Results
- For the first problem: The
ScrollTop
component should become visible after scrolling a certain distance. - Concerning the second challenge: Clicking on the
ScrollTop
component should return the screen to the top of the page.