O
O
Olga2018-02-01 21:34:44
React
Olga, 2018-02-01 21:34:44

How to do without state?

to define scrolling (up/down) I use a function that hangs on the 'scroll' event.

scrollUpDown() {
    if (this.state.lastScrollPos < getScrollTop() ) {
      this.setState({lastScrollPos: getScrollTop()});
      console.log('down')
    }
    else if (this.state.lastScrollPos > getScrollTop() ) {
      this.setState({lastScrollPos: getScrollTop()});
      console.log('up')
    }
  }

how can I check scrolling without using work with state?
getScrollTop() - cross-browser function to determine the number of scrolled pixels

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kn1ght_t, 2018-02-02
@melkaya94

if you do not need a component re-render, you can simply create a static variable inside the component class and save it to it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question