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

Event handlers functiion created at every re-render? #182

Closed
tiye opened this issue Jun 23, 2015 · 2 comments
Closed

Event handlers functiion created at every re-render? #182

tiye opened this issue Jun 23, 2015 · 2 comments

Comments

@tiye
Copy link

tiye commented Jun 23, 2015

Code here https://github.com/dekujs/todomvc/blob/master/client/todo-item/index.js#L26

Came from React, which puts methods on this and render looks clean, Deku's solution looks quite messy to me. And during every render, function like onClick in the example below are created.

render: function() {
  var onClick = function(){}
  return <div onClick={onClick}>Click</div>
}

Would that cause performance issues? Would it bother features like hot module replacement?

@anthonyshort
Copy link
Owner

You can put the functions anywhere you want, the handlers are passed everything you'll need:

function render (component) {
  return <div onClick={onClick}>Click</div>
}

function onClick (event, component, setState) {
  // do anything
}

In some of the examples we put the functions inside when they're really simple. Hope that helps!

@tiye
Copy link
Author

tiye commented Jun 23, 2015

So that onClick is called with component and setState. Didn't notice that. It's helpful.

Also found in docs https://github.com/dekujs/deku#event-handlers

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

2 participants