Jason Chen
Jason Chen

Reputation: 2577

How do I template with Reactjs?

I initially had this done via PHP includes, but React started giving me problems once I started nesting variables. This means that now I have giant containers of returns. For instance...

if (this.state.transitiontime){
return (
<div id="stuff">
//lots of html content//
</div>
);} 

What would be the best way to separate the //lots of html content// into a separate file?

When I did it in PHP I did like so...

if (this.state.transitiontime){
return (
<div id="stuff">
<?php includes('htmlcontent.php');?>
</div>
);} 

Upvotes: 1

Views: 59

Answers (1)

TJR
TJR

Reputation: 6577

You would use Components you've written in ReactJS. For example you will be able to include your Component "SomeComponent" when using JSX like this:

if (this.state.transitiontime){
return (
<div id="stuff">
   <SomeComponent />
</div>
);} 

Take a look at this: ReactJS Multiple Components

Upvotes: 2

Related Questions