wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

rt-stateless passing of props #231

Closed ajchang84 closed 6 years ago

ajchang84 commented 6 years ago

Dear developers of react-templates,

I have a question about the usage of rt-stateless:

Normally, we render our component templates like this in the javascript: render() { return template.apply(this) } However, for rendering of the stateless component, how do I pass in custom props in the javascript to be used in the rt-stateless template?

nippur72 commented 6 years ago

I'm not sure you are doing it correctly. As far as I know the .apply(this) call is not necessary because react automatically binds to this when calling the render() function.

Anyway if you still want to maintain the apply() call, you have to do something like this:

render(props, context) { return template.apply(this, [props, context]) }
// or better
// render(props, context) { return template.call(this, props, context) }
ajchang84 commented 6 years ago

Oops, all this time we've been returning with an .apply(this)! Thanks a lot for the insight

Got it to work now and keep up the great work with react-templates, it's been invaluable.