I guess I'm old fashioned and build strings of HTML and data. Was expecting React would handle this nicely when I return the string. Is there and obvious approach? And <br> doesn't seem to work any place. Is there a substitute?
(Below: Cut and paste into an .html file and it'll run.)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="root"></div>
<script type="text/babel">
var SportsPeople = [
{thegame: 'Football', name: 'Tom Brady' },
{thegame: 'Basketball', name: 'Le Bron James' }
]
class Banner extends React.Component {
constructor(props) { super(props); };
render() { return ( <div>Big Banner on the Top</div>); }
}
class AnotherLine extends React.Component {
constructor(props) { super(props); };
render() {
let htmlStuff = "";
let workTable = this.props.stars;
for (let i = 0; i < workTable.length; i++)
{
htmlStuff += workTable[i].thegame;
htmlStuff += "<p> - </p>";
htmlStuff += workTable[i].name;
htmlStuff += "<br>";
}
console.log ( { htmlStuff } );
return ( <div> { htmlStuff } </div> );
} // End render
} // End CLASS
//==============================
class Main extends React.Component {
constructor(props) { super(props); };
render() {
return (
<div>
<Banner />
<AnotherLine
stars = { SportsPeople }
/>
</div>);
}
}
// =========================================
ReactDOM.render(
<Main />,
document.getElementById('root')
);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script>
</body>
</html>