1

Consider the following Component hierarchy:

var FundComponent = React.createClass({
    render : function() {
      return (
        <div>
        <UserComponent profile={data} />
        </div>
        );
    }
  });

var UserComponent = React.createClass({
    render : function() {
      return (
        <div>
        Some Stuff goes here
        </div>
        );
    }
  });

React.renderComponent(<FundComponent />, document.getElementById('fund'));

This will render UserComponent inside the #fund node in my HTML.

How can I render UserComponent in a specific node inside the fund node in my HTML ? eg:

<div id="fund">
<div id="otherStuff">Stuff</div>
<div id="user">**load UserComponentHere**</div>
</div>

2 Answers 2

1

After reading around a bit, I found out how to go about this. Feel free to correct me.

React has a different concept as to how to go about this.

Rather than pre-defining the html in the html file, we define it in the render function, like so:

var FundComponent = React.createClass({
    render : function() {
      return (
        <div>
          <div className="myOtherStuff1">
            <OtherComponent1 data={data} />  //other stuff
          </div>
          <div className="user">  //user
            <UserComponent profile={profile} />
          </div>
          <div className="myOtherStuff2">
            //can have component or other static stuff. Upto developer.
          </div>
          ...
        </div>
      );
    }
  });

React.renderComponent(<FundComponent />, document.getElementById('fund'));

And the html will be: <div id="fund"></div>

And then, we can define UserComponent and OtherComponent(s) as we go.

Sign up to request clarification or add additional context in comments.

Comments

0

I may be misunderstanding you, but you should simply be able to do:

React.renderComponent(<FundComponent />, document.getElementById('user'));

to render into the #user div.

1 Comment

What if Fund component holds other components too ? And each needs to be in a different node within Fund component ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.