# Push\_event from components

**URL:** <https://forum.elixirforum.com/t/push-event-from-components/39842>\
**Category:** Questions\
**Tags:** phoenix, event, liveview, livecomponents\
**Created:** [May 20, 2021, 10:43am UTC](https://forum.elixirforum.com/t/push-event-from-components/39842 "2021-05-20T10:43:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![larshei](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/larshei/32/20660_2.png) [@larshei](https://forum.elixirforum.com/u/larshei)\
**Post date:** [May 20, 2021, 10:43am UTC](https://forum.elixirforum.com/t/push-event-from-components/39842/1 "2021-05-20T10:43:24Z")

</div>

**What I want to achieve**

I am currently building a small frontend displaying a JavaScript based map, with markers for positions of assets. The map itself is a Component.

There are basically just two pages:

1. An overview page listing all assets
2. A detail page per asset.

I can update the map using `push_event/3`, what works well on the details page:  
There are two events, _add\_asset_ and _update\_asset_.  
On mounting the liveview, the asset is added to the map.  
When new data comes (in my case in a handle\_info), the asset position is updated.

I would like to add a map to the overview page, listing all assets positions.

**What I tried to achieve this**

As there already is a function to add an assets position to the map, I thought I’d just use that.  
The overview page renders a bunch of Components, of which one is the map.  
The other components are simply list entries, one per asset. All components are stateless.  
I tried to `push_event/3` an _add\_asset_ event from each components `update()` callback.

**Expected behaviour**  
I would have expected each asset to be added to the map.

**Actual behaviour**  
Nothing is added.  
Each attempt to add an asset should trigger a console.log(), but nothing is logged.

**Question**  
Seems like the events are never actually pushed out to browser.  
Does pushing events from within a components update() function not work?  
Or maybe, do these occur before the socket connection is established?

---

<div class="post-metadata">

**Author:** ![tomkonidas](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tomkonidas/32/22982_2.png) [@tomkonidas](https://forum.elixirforum.com/u/tomkonidas)\
**Post date:** [May 20, 2021, 7:07pm UTC](https://forum.elixirforum.com/t/push-event-from-components/39842/2 "2021-05-20T19:07:11Z")

</div>

When you [push\_event/3](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#push_event/3) your are pushing an event to the client to be consumed by hooks. So you would have to have a JS hook that would catch that event to send back to the backend.

Are these 2 pages different live views? (i.e. Listing.Index and Listing.Show)

Are you mounting the live\_component in each view?

Can you paste some code so we can maybe see a little whats going on?

Your JS hooks, LiveView(s) and your component would be sufficient
