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 embed a component in another? #4

Closed
volkanunsal opened this issue Nov 18, 2013 · 1 comment
Closed

How to embed a component in another? #4

volkanunsal opened this issue Nov 18, 2013 · 1 comment

Comments

@volkanunsal
Copy link

I have a question about how to nest two React components using your library/ Say I have 2 components:

SidebarView = React.createBackboneClass({
  render: function() {
     var coll = this.getModel();
      return (
        <section role="sidebar">
          <UserView />
        </section>
      );
    }
});

UserView = React.createBackboneClass({
    changeOptions: "change:name, change:life", // DEFAULT is "change",
    render: function() {
       var coll = this.getModel();
        return (
          <h1>
            {coll.map(function(model) {
              return <i>{model.get("name")}:{model.get("life")}</i>;
            })}
          </h1>
        );
      }
});

I can embed the UserView in SidebarView, but that is not going to have the state in the model. And when I try adding the instance of the UserView into SidebarView, it doesn't work –– or maybe I couldn't make it work. Can you please elaborate on how to do this? Maybe add an example in the README file?

@clayallsopp
Copy link
Owner

You need to pass the model as a property when creating the view:

SidebarView = React.createBackboneClass({
      ...
      return (
        <section role="sidebar">
          <UserView model={this.getModel()} />
        </section>
      );
});

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