re-frame/docs/FAQs/Null-Dispatched-Events.md

22 lines
816 B
Markdown
Raw Normal View History

2016-08-29 13:06:41 +00:00
### Question
2016-08-29 12:57:35 +00:00
If I `dispatch` a js event object (from a view), it is nullified
by the time it gets to the event-handler. What gives?
2016-08-29 13:06:41 +00:00
### Answer
2016-08-29 12:57:35 +00:00
So there's two things to say about this:
- if you want to `dispatch` a js event object to a re-frame
event handler, you must call `(.persist event)` before the `dispatch`.
React recycles events (using a pool), and re-frame event handlers
run async. [Find out more here](https://facebook.github.io/react/docs/events.html)
- it is probably more idiomatic to extract the salient data from the event
and `dispatch` that, rather than the js event object itself. When you
`dispatch` pure, simple cljs data (ie. rather than js objects) testing
and debugging will become easier.
2016-08-29 13:06:41 +00:00
---
Up: [FAQ Index](README.md)