A
A
Arthur Morphy2021-06-18 19:16:48
React
Arthur Morphy, 2021-06-18 19:16:48

Loading content on income until the end of the block?

or at least 70% so that the height of the scroll is passed before the callback is called

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
n1ksON, 2021-06-19
@Cryfear

import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Home from './pages/Home';

const App = () => {
  const dispatch = useDispatch();
  const { data } = useSelector((store) => store);

  const [allowScroll, setAllowScroll] = useState(true);

  const scrolling = () => {
    const height = Math.max(
      document.body.clientHeight,
      document.documentElement.clientHeight
    );
    if (
      window.pageYOffset > height * 0.75 ||
      window.pageYOffset > height - 2000
    ) {
      if (allowScroll) {
        setAllowScroll(() => false);
        setTimeout(() => {
          setAllowScroll(() => true);
        }, 2000);
        dispatch({
          type: 'DISPATCH',
        });
      }
    }
  };

  return (
    <div onWheel={scrolling}>
      <Home />
    </div>
  );
};

export default App;

S
Simkav, 2021-06-18
@Simkav

Through useEffect, throw the listener on the scroll of the page, and there do magic with checking for the current height

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question