> For the complete documentation index, see [llms.txt](https://docs.payengine.co/developer-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payengine.co/developer-docs/getting-started-1/8.-handling-callbacks-from-web-components.md).

# 8. Handling Callbacks from Web-Components

Events are our way of letting you know when something interesting happens in web-components.

The `pay-engine` web-component is a DOM element that provides various events to which you can attach listeners to in your client side code. For specific events, please refer to following document:

* [Onboarding web-component](https://docs.payengine.co/developer-docs/getting-started-1/pages/-MTHswR5G-dPad8clHO2#3.-events)

To attach an event handler to web-component, you'll need to call `addEventListener` on your desired web-component element.

```
<pay-engine id="onboarding" merchant-id="ea0e0ae6-aa42-48da-b801-0106facf1e37" type="boarding"></pay-engine>

<script type="application/javascript">
    document.getElementById('onboarding').addEventListener('stepChange', function(e) {
        console.log(e.detail)
    })
    document.getElementById('onboarding').addEventListener('submitted', function(e) {
        console.log(e.detail)
    })
</script>
```

Below you'll find some equivalent examples in other popular frameworks.

## React

```
function MyComponent() {

    const addEvents = useCallback(node => {
        if (node !== null) {
            node.addEventListener('stepChange', function(e) {
                console.log('step changed', e.detail);
            })
        }
    });
    
    return <pay-engine 
        ref={addEvents} 
        merchant-id="ea0e0ae6-aa42-48da-b801-0106facf1e37" 
        type="boarding"></pay-engine>
}
```

## VueJS

```
<template>
    <pay-engine
        @step-change="stepChange"
        merchant-id="ea0e0ae6-aa42-48da-b801-0106facf1e37" 
        type="boarding"></pay-engine>
</template>

<script>
export default {
    methods: {
        stepChange(event) {
            console.log('step changed', event);
        }
    }
}
</script>
```

## Angular

```
// onboarding.component.html
<pay-engine
        (stepChange)="stepChange"
        merchant-id="ea0e0ae6-aa42-48da-b801-0106facf1e37" 
        type="boarding"></pay-engine>
        
// onboarding.component.ts
export class OnboardingComponent implements OnInit {
        onInit(): void {
        
        }
        
        stepChange(event: any) {
                console.log('step changed', event);
        }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.payengine.co/developer-docs/getting-started-1/8.-handling-callbacks-from-web-components.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
