wix-incubator / react-templates

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

Template Inheritance; this.props is undefined #195

Closed bencripps closed 7 years ago

bencripps commented 7 years ago

This is my main template

<rt-import name="default" as="Header" from="./../component/shared/header/index.rt"/>
<div>
   <Header />
   {  this.props.children }
</div>

And the secondary Template that uses it:

<rt-import name="default" as="Main" from="./main.rt"/>
<Main>
  <span>This is a secondary page</span>
</Main>

If I remove the this.props.children from the main.rt this document loads. How can I nest my components, and why is this.props undefined here?

bencripps commented 7 years ago

At the template scope this is an empty object.

nippur72 commented 7 years ago

you cant import main from main.rt because it does not contain the whole component but only the render function. You might turn main into a stateless component (and drop the "this" from "this.props.children").

bencripps commented 7 years ago

Yup, that was it! Thanks!