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 to pass data from Layout to child #28

Closed
vladshcherbin opened this issue Oct 21, 2015 · 3 comments
Closed

How to pass data from Layout to child #28

vladshcherbin opened this issue Oct 21, 2015 · 3 comments
Labels

Comments

@vladshcherbin
Copy link

Okay, I've got a small question. We have a route:

FlowRouter.route('/test', {
  name: 'admin.permissions.index',
  action: function () {
    ReactLayout.render(AdminLayout, {
      content: <AdminPermissionsIndex />
    });
  }
});

So, in the top AdminLayout we have getMeteorData() and render:

getMeteorData() {
  return {
    currentUser: Meteor.user()
  };
},
render() {
  <section>
    {this.props.content}
  </section>
}

Now I need to pass this.data.currentUser as props to its child (AdminPermissionsIndex). Am I doing it right and how can I do it?

@arunoda
Copy link
Contributor

arunoda commented Oct 21, 2015

Then it's kind a hard to get it. Try to do it in a component below the layout. Think, layout component simply does basic layouts and does not deal with reactive data.

@vladshcherbin
Copy link
Author

@arunoda thanks for the quick reply, but I don't get it. The top component (Layout) is what needs to control all components below, no? So, what you proposing is:

<AppComponent> (does nothing, only has the place to insert smth)
  <AdminLayout> (has reactive data and passes to children)
    <AdminPermissions> (finally has the props)

So, I cant pass smth like ReactLayout.render(AppComponent, {content: <AdminLayout />}); because it will be the same for all routes.

The only way is to have getMeteorData in all templates. Am I missing something?

@andersr
Copy link

andersr commented Mar 1, 2016

This, to me, this is a fundamental flaw in the design of FlowRouter/react-layout. It should be easy to pass props down from the top-level component. Not being able to do so, imo, contradicts the thinking behind React and forces users of FlowRouter to resort to hacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants