N
N
nivaech2020-08-21 14:44:14
JavaScript
nivaech, 2020-08-21 14:44:14

How to change the state of a component on scroll?

There is a Collapse component, with material-ui that hides some content.

<Collapse in={collapsed}>
          <div>Some Content</div>
        </Collapse>


And here is its state, by changing which the component should hide the content.
const [collapsed, setCollapsed] = React.useState(true);

  const handleCollapse = () => {
    setCollapsed(collapsed => !collapsed);
  };


We want the state of the component to change as soon as the user starts scrolling down to hide the content. Does anyone know how to accomplish this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
t800zippygod, 2020-08-21
@t800zippygod

Yes, you can hang an event handler on a component through the React synthetic event - onWheel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question