Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Passing a callback to a component - possible?

$
0
0
I often create components that need to return some result to the parent component. Couple of approaches I have done:

- Pass an object to the sub component and have that sub component modify the object directly, I am not really fond of this approach, I don't want sub components modifying the state of my objects.

- Have the component trigger DOM events, this works well, but it always feels like it is more work than was is needed.

Another approach that I would like to use is to simply pass a callback function to the sub component. I have seen React using this method:

  1. <FundooRating value={this.state.rating} max="10" onRatingSelected={this.handleRatingSelected} />

I'm trying to replicate this in CanJS, but can't make it work yet. Please see this fiddle

Is it possible? What I'm missing?

Viewing all articles
Browse latest Browse all 3491

Trending Articles