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

How do you pass props down through ReactLayout and {this.props.content}? #42

Open
czbaker opened this issue Dec 6, 2015 · 1 comment

Comments

@czbaker
Copy link

czbaker commented Dec 6, 2015

So, I'm rending stuff using ReactLayout (as a 'layout manager'), and what I'm having problems understanding is...how are you supposed pass props down from App -> Layout -> Page, if you can't (I don't see how) pass props down through {this.props.content}?

Say I have a function thisFunc() in App that I want to pass down to a grandchild component...how're you supposed to go about that? Ordinarily, I'd just do something like , but since you're using {this.props.content} to render components...I don't know how the chain is supposed to work.

Insights?

@benlwong
Copy link

benlwong commented Dec 9, 2015

I had the same question. I stumbled upon this answer given in the comment section: https://kadira.io/academy/meteor-routing-guide/content/rendering-react-components#comment-2340835669

Basically, you change the layout template code from:

MainLayout = React.createClass({
  render() {
    return <div>
      <header>
        This is our header
      </header>
      <main>
        {this.props.content}
      </main>
      <footer>
        This is our footer
      </footer>
    </div>
  }
});

to

MainLayout = React.createClass({
  render() {
    return <div>
      <header>
        This is our header
      </header>
      <main>
        {React.cloneElement(this.props.content, {someProp: this.thisFunc})}
      </main>
      <footer>
        This is our footer
      </footer>
    </div>
  }
});

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