Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

How to do event binding on component? #122

Closed
jfrux opened this issue May 15, 2018 · 6 comments
Closed

How to do event binding on component? #122

jfrux opened this issue May 15, 2018 · 6 comments

Comments

@jfrux
Copy link

jfrux commented May 15, 2018

When I do like onPlay={() => {}} or something along those lines, its causing react-tv renderer to throw errors in browser like Unexpected token (.

On react-dom it works fine.
What is a way I can do this without it throwing this error? I REALLY want to use this renderer but this is keeping me from rendering videos for some reason.

UPDATE:
It seems to be doing it with my more dynamic components like ones that use: createElement

Any tips? Anybody done this?

@raphamorim
Copy link
Owner

Sorry about the delay, @joshuairl.
Well, maybe now it's better to try to use with React-DOM. I'm working on React-TV 0.4 version with full improve on memory usage (#123) and creating a development version to catch these type of errors.

@jfrux
Copy link
Author

jfrux commented May 19, 2018 via email

@jfrux
Copy link
Author

jfrux commented Jun 3, 2018

Assuming this is fixed now then?

@jfrux
Copy link
Author

jfrux commented Jun 3, 2018

Nah it just doesn’t work

@robolivable
Copy link

robolivable commented Oct 12, 2018

I ran into the same issue, @jfrux.

This issue is apparently due to react-tv not properly handling event emitters. The cryptic Unexpected token ( error you're seeing is caused by passing in an anonymous function to the Element.setAttribute method when setting an element's event listener property. You can get the error to go away by passing in a named function as a value for the event. Here's a jsfiddle example of what I mean. Keep in mind though that since setAttribute works differently than using a dot accessor for setting the value, you will likely have to call toString on your function when you pass it in... This also limits you from passing in any scoped functions, for example, a prototype method will just be rendered as function myFunc() { [native code] }, which would just throw a similar Unexpected token error as a result. My work around for this was to just pass in static methods (or just inline function expressions) and use globals to achieve dynamic functionality (e.g., persisting a value of an input in sessionStorage on onKeyDown ... super hacky, I know, I would appreciate any better ideas).

Side note, while digging through react files I was blown away by the intricacies surrounding the events module responsible for managing element on events...

@marcus-sa
Copy link

marcus-sa commented Oct 12, 2018

Only workaround is instead of using an anonymous function, you should put in a named function:

onPlay(myFn)

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

No branches or pull requests

4 participants