# Perspective Component Handling Message

**URL:** <https://forum.inductiveautomation.com/t/perspective-component-handling-message/94226>\
**Category:** Module Development\
**Tags:** perspective\
**Created:** [August 6, 2024, 3:16pm UTC](https://forum.inductiveautomation.com/t/perspective-component-handling-message/94226 "2024-08-06T15:16:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [August 6, 2024, 3:16pm UTC](https://forum.inductiveautomation.com/t/perspective-component-handling-message/94226/1 "2024-08-06T15:16:01Z")

</div>

I'm writing my first Perspective component that will be receiving messages from the gateway, and I just wanted to confirm my understanding on the javascript side.

I've written a ComponentStoreDelegate:

```python
export class MaterialTreeMessageHandler extends ComponentStoreDelegate {
	handleEvent(eventName: string, eventObject: JsObject): void {
		console.log('handling event', eventName, eventObject);
		this.notify();
	}
}

```

Then in my component I can subscribe with:

```python
	props.store.delegate?.subscribe(() => {
		console.log("message received");
	})

```

To pass the actual message data, am I supposed to be implementing `mapStateToProps` in the message delegate and then directly accessing it via:

```python
props.store.delegate.myPropertyName

```

Also, is there a difference between `props.delegate` and `props.store.delegate`?

---

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [August 8, 2024, 10:40pm UTC](https://forum.inductiveautomation.com/t/perspective-component-handling-message/94226/2 "2024-08-08T22:40:26Z")

</div>

Am I understanding this correctly? I have something that sort of works, but wanted to make sure this is the "intended' usage...

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 8, 2024, 10:42pm UTC](https://forum.inductiveautomation.com/t/perspective-component-handling-message/94226/3 "2024-08-08T22:42:47Z")

</div>

I looked at this a bit, but quickly ran out of time and knowledge. I don't see anything readily wrong with what you're doing.

> [@cody.tamaki](#):
>
> mapStateToProps

From what I can tell, implementing this is entirely optional.

> [@cody.tamaki](#):
>
> is there a difference between `props.delegate` and `props.store.delegate`?

I don't _think_ so.

---

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [August 8, 2024, 10:44pm UTC](https://forum.inductiveautomation.com/t/perspective-component-handling-message/94226/4 "2024-08-08T22:44:45Z")

</div>

Awesome - thank you for taking the time to respond!
