# Renderless Components

Using components to deal with non-presentational concerns is an extremely powerful pattern that is often overlooked.

One example we use in Shopify is the `<EventListener />` component, which is a useful component for adding event listeners on `window` that automatically manages adding the listeners on mount and cleaning them up on un-mount.

Its implementation looks something like this, though we’ve simplified it a little for the sake of this example:

```javascript
class EventListener extends React.Component {
  static propTypes = {
    eventName: PropTypes.string,
    handler: PropTypes.func,
  };

  componentDidMount() {
    const {eventName, handler} = this.props;
    window.addEventListener(eventName, handler);
  }

  componentWillUnmount() {
    const {eventName, handler} = this.props;
    window.removeEventListener(eventName, handler);
  }

  render() {
    return null;
  }
}
```


---

# 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://shopify-1.gitbook.io/react/4.-advanced-patterns/renderless-components.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.
