Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

->clj with React events #77

Open
Hendekagon opened this issue Feb 29, 2020 · 3 comments
Open

->clj with React events #77

Hendekagon opened this issue Feb 29, 2020 · 3 comments

Comments

@Hendekagon
Copy link

I've tried using ->clj with mouse events in a Reagent app with both (fn [e] (->clj e) ...) where the fn is the handler for the event, but it doesn't convert (it remains JS object). Using ->clj on the event's .-nativeEvent doesn't work either - what should I do ?

@mfikes
Copy link
Owner

mfikes commented Feb 29, 2020

Seems similar to #76

@stevebuik
Copy link

I've experienced this as well. data coming from a callback in a separate react lib built with typescript.

Fortunately I maintain the typescript lib so I was able to workaround by converting all data to plain js objects (using Object.assign) and then both ->clj and recursive bean worked fine.

Before the workaround, object? was false and then true for the plain js objects.

Not ideal for people using 3rd party libs where they can't use the same workaround at the source.
However it should be possible to write an extra fn in cljs with interop until this lib can handle typescript/react js objects.

@jaidetree
Copy link

Ran into this myself on several occasions. Worth mentioning is that not even js->clj works on React events or native events because they are not plain objects, they are specific classes that I don't think implement the mechanisms that functions like js->clj and bean rely on to collect props into a map.

Most of the time I've used lightweight functions to transform the events to clj maps:

(defn event->map
  [e]
  {:type           (.-type e)
   :target         (.-target e)
   :current-target (.-currentTarget e)
   :prevent-default #(.preventDefault e)
   ;; ... other keys if needed
   })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants