# Waypoint

Use `https://github.com/thebuilder/react-intersection-observer` instead its faster cuz new browser api

Run a function when a waypoint is reached

```bash
yarn add react-waypoint
```

A waypoint normally fires `onEnter` and `onLeave` as you are scrolling, but it can fire because of other events too:

* When the window is resized
* When it is mounted (fires `onEnter` if it's visible on the page)
* When it is updated/re-rendered by its parent

#### Uses

* infinite scroll
* Change, add CSS on scroll

## Example

```jsx
 import { Waypoint } from "react-waypoint";

class MenuBar extends Component {
  state = {
    scrolled: false
  };
  
   handleWaypointEnter = () => {
      this.setState({ scrolled: false });
    };

    handleWaypointLeave = () => {
      this.setState({ scrolled: true });
    };
  
  render() {
    const navClass = classNames(
        "navbar",
        { "add-nav-shadow": this.state.scrolled }
      );
    return (
      <Waypoint
        onEnter={this.handleWaypointEnter}
        onLeave={this.handleWaypointLeave}
        />
  	)
  }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openai.gitbook.io/code-cheatsheets/react/packages/waypoint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
