Tell us what’s happening:
Hello, I keep solving challenges on react and repeatedly see the pattern: a class is referred before it is declared. Like in the challenge below: first we reference Navbar in the MyApp class and then we declare the Navbar class. Can anyone explain please why it works? Thank you.
Your code so far
class MyApp extends React.Component {
constructor(props) {
super(props);
this.state = {
name: 'CamperBot'
}
}
render() {
return (
<div>
{/* Change code below this line */}
<Navbar />
{/* Change code above this line */}
</div>
);
}
};
class Navbar extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
{/* Change code below this line */}
<h1>Hello, my name is: </h1>
{/* Change code above this line */}
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: React - Pass State as Props to Child Components
Link to the challenge: