Tips for utilizing the React Page Scroller with a webpage exceeding 100vh in size

I'm currently facing an issue with React Page Scroller. While most components I'm using are set to take up 100vh and work smoothly with React Page Scroller, the problem arises with the footer, which exceeds the 100vh limit. I attempted to place the footer outside of the ReactPageScroller component, but this resulted in two vertical scrolls on the screen. This means that it scrolls down to the next component but also scrolls down to the footer.

<ReactPageScroller>
  <SomeComponent />
  <SomeComponent />
  <SomeComponent />
  <SomeComponent />
  <Footer />
</ReactPageScroller>

or

<ReactPageScroller>
  <SomeComponent />
  <SomeComponent />
  <SomeComponent />
  <SomeComponent />
</ReactPageScroller>
 <Footer />

Any suggestions on how to approach this issue? The goal is to be able to scroll normally down to the footer once I reach the last component, and then still have the React Page Scroller effect when scrolling back up. If my explanation is unclear, please feel free to ask for clarification.

Answer №1

During my research, I came across something related to scrollers called pageOnChange props:
I found examples of implementation using React Class Components, so I assumed your component is a class type.
First, I initialized a state object like this:

 this.state = {
      currentPage: 1,
      isFooterVisible: false
    };

Then, I created a function to update the state on a page change event:

 pageOnChange = (number) => {
    this.setState({
      currentPage: number,
      isFooterVisible: number === 6 // 6 represents the last component number 
    });
  };

I added this function to the pageOnChange={this.pageOnChange} of ReactPageScroller:

  <ReactPageScroller
          ref={(c) => (this._pageScroller = c)}
          pageOnChange={this.pageOnChange}
        >

To render the footer component, I used conditional rendering with this.state.isFooterVisible like this:

  <>
        <ReactPageScroller
          ref={(c) => (this._pageScroller = c)}
          pageOnChange={this.pageOnChange}
        >
          <Comp title={"PAGE 1"} />
          <Comp title={"PAGE 2"} />
          <Comp title={"PAGE 3"} />
          <Comp title={"PAGE 4"} />
          <Comp title={"PAGE 5"} />
          <Comp title={"PAGE 6"} />
        </ReactPageScroller>
        {this.state.isFooterVisible && <Footer />}
      </>

I also added the following rules to the global CSS file:

html {
  overflow: hidden;
  width: 100%;
}

body {
  height: 100%;
  position: fixed;
  /* prevent overscroll bounce*/
  background-color: lightgreen;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
}

Below is the complete code for the component:

import React from "react";
import ReactPageScroller from "react-page-scroller";
import Comp from "./component";
import Footer from "./footer";

export default class Scroller extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      currentPage: 1,
      isFooterVisible: false
    };
    this._pageScroller = null;
  }

  goToPage = (eventKey) => {
    this._pageScroller.goToPage(eventKey);
  };

  pageOnChange = (number) => {
    this.setState({
      currentPage: number,
      isFooterVisible: number === 6
    });
  };

  render() {
    return (
      <>
        <ReactPageScroller
          ref={(c) => (this._pageScroller = c)}
          pageOnChange={this.pageOnChange}
        >
          <Comp title={"PAGE 1"} />
          <Comp title={"PAGE 2"} />
          <Comp title={"PAGE 3"} />
          <Comp title={"PAGE 4"} />
          <Comp title={"PAGE 5"} />
          <Comp title={"PAGE 6"} />
        </ReactPageScroller>
        {this.state.isFooterVisible && <Footer />}
      </>
    );
  }
}

https://codesandbox.io/s/elegant-shape-j0u4c?fontsize=14&hidenavigation=1&theme=dark

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Position a div in the center and add color to one side of the space

I am seeking a way to create a centered div with the left side filled with color, as shown in examples. I have devised two solutions without using flexbox, but both seem somewhat like hacks. body { margin: 0; padding: 0; } .header { width: ...

picture located in the top corner of the page within the diva triangle shape

Is there a way to position my photo on the same level as a div and have it overlap slightly? <div id='triangle-topleft'> <img id="photo" src="photo.png"> </div> #triangle-topleft { width: 0; heigh ...

Problem encountered when attempting to insert a new division into an existing flexbox container

I'm in the process of designing a basic login page using HTML/CSS. To center the box on the screen, I opted for a flexbox layout. So far, I have successfully positioned the Username/password fields and login button just the way I want them. The only t ...

What are some creative ways to design drop-down menus within an email?

The snippet of code I am currently using lacks the ability to format text, and it does not allow content below dropdown items to shift down properly in an email. <select> <option value="first">First-time users of the Vanguard Events app:&l ...

Updating the Spline/canvas rendering when switching pages in Next.js/ReactJS

After creating a 3D design Spline, I wanted to export it to my website. The Spline worked well on the Home page, but when switching to the About page, it had to re-render causing some issues. Here are screenshots for reference: View from the Home page T ...

The .map() function is failing to produce a new array when utilizing the return function

For a React challenge, I was tasked with creating a card that generates a specific number of random numbers based on user input. To achieve this, I wrote a function called "getRandomNum" to generate random numbers within a given range and check if they a ...

Font sizing does not adapt properly for larger screens in MUI 5

I have integrated Material UI v5 into my React application. Utilizing the responsiveFontSizes feature to create responsive typography settings based on the options provided. Although the responsiveFontSizes functionality is effective for various device s ...

The style fails to load correctly upon the page's initial loading

I am utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d26282823603e212429283f0d7b63756378">[email protected]</a> in a <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="026c677a76 ...

Node.js has no trouble loading HTML files, however, it seems to encounter issues when trying to

Having a bit of trouble with my JavaScript skills as I try to load my index.html file (seems like it should be the 5th easiest thing to do in JavaScript). Let me get straight to the point; when I manually open my index.html, it loads perfectly WITH the CS ...

The functionality of the tree-view feature in NodeJs is experiencing glitches

My attempt at creating a Tree-view has hit a snag. The collapse icon is not being displayed as expected. Here is the code snippet I tried: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootst ...

React encountering Eslint issue with callback hooks usage

Utilizing callback hooks has been instrumental in preventing the re-rendering of components that are affected by a change in the function passed as props. I have incorporated callback Hooks into both incrementSalary and incrementAge. It appears that the ca ...

What is the best way to include a borderTop in a React Material UI Table component?

https://i.sstatic.net/RIViY.png Is there a way to add a top border to the table above? I attempted const styles = theme => { root : { borderTopWidth: 1, borderColor: 'red'} } ... class TableComponent ... { classes } = this.props; & ...

When beginning a test with Jest, an error has occurred in NextJs stating: "TypeError: replace is not a function"

This is a NavBar component that includes a search input. When used, it redirects to another page displaying the search results. The redirection method being utilized here is using "replace" instead of "push". import React, { useEffect, useState } f ...

Hide the scroll bar in html/css while keeping the functionality of the arrows intact

Is there a way to remove the scroll bar but still be able to access overflown data using arrows? Any assistance would be greatly appreciated. Thank you in advance. ...

Displaying a component inside a different component

I'm attempting to display components inside another component, but even when I try to include div elements within the component, they don't show up. const DisplayComponent = () => { return ( <div> <DisplayContent ...

What could be causing my website to function flawlessly in Firefox but not in Chrome or Internet Explorer?

Hey everyone, I'm feeling lost and have been comparing files using DiffNow. I don't have any code to offer because I'm unsure of where to even begin. The website is coded in php/html/mysql/jquery. Here are my main concerns: -Animations are ...

Leveraging colons in the process of object destructuring

I'm still trying to wrap my head around all the wonders of ES6. Ran across this snippet in an online article and I'm puzzled by how PrivateRoute is deconstructing the input props. What exactly is the purpose of component: Component here? const P ...

Troubleshooting React's Sortable Order Functionality

https://i.sstatic.net/jnFqv.gif While sorting the items in the list, it appears that the placeholder element is getting overlapped by the others. The code logic I am using is very similar to this example. The gray background is an element positioned ab ...

Having difficulty retrieving data from inner join table using axios in React

As a newcomer to React, I'm attempting to populate fields with data retrieved from Express using Axios. However, I am encountering difficulties when trying to display data from a joined table. import React, { Component } from "react"; import FilmesDa ...

Utilize the power of React and Framer Motion to create a visually stunning fade

After creating a preloader that appears when the variable "loading" is set to true, I now want the loader to fade out. This is an overview of my files: On the home page with all the content: return ( <> {loading ? ( ...