I am trying to render an instance of a Component Class from another Component Class in React. But for some reason, the browser complains that the component instance is not defined. I have it all in the same JS file (JS window in Codepen). Here's my code -
var NavBar = React.createClass({
render: function() {
var pages = ['home', 'blog', 'pics', 'bio', 'art', 'shop', 'about', 'contact'];
var navLinks = pages.map((page) => {
<a href="{'/' + page}">{page}</a>
});
return <nav>{navLinks}</nav>;
}
});
var Page = React.createClass({
render: function() {
return (
<div>
<h1 className="text-primary">Welcome!</h1>
<NavBar />
<h2 className="text-primary">About Me</h2>
</div>
);
}
});
ReactDOM.render(<Page />, document.getElementById('app'));
Here's the app on Codepen. This is the error I get -
pen.js:13 Uncaught ReferenceError: NavBar is not defined
I'm not quite sure what's going on. NavBar should be available in the scope of Page, as far as I understand.
Thanks!
.mapaddreturnstatement or usepages.map((page) => (<a href="{'/' + page}">{page}</a>));. Also don't forget addkeyfor element inside loopreturncreates a problem here, when it seems to work here -var multiply = (x, y) => x*y;Thanks for the help!