At the end of this class, you will be able to:
wilson-espina/jsd-9-resources
repo to your computerDocuments/JSD/jsd-9-resources/18-react
React is JavaScript library from Facebook, that is designed to create interactive UIs.
function Welcome(props) {
return Hello, {props.name}
;
}
Open up: 00-functional-component-codealong
const listItems = numbers.map((number) => {
return {number}
});
// return statement in component
return (
{listItems}
);
[
'cheese',
'lettuce',
'cucumber'
]
maps to
[
'<li>cheese</li>',
'<li>lettuce</li>',
'<li>cucumber</li>',
]
[
'<li>cheese</li>',
'<li>lettuce</li>',
'<li>cucumber</li>',
]
rendered as
<li>cheese</li>
<li>lettuce</li>
<li>cucumber</li>
props = {
firstName: 'Mary',
lastName: 'Richardson'
}
return <Greeting {...props} />;
is parsed as
return <Greeting firstName="Mary" lastName="Richardson" />;
Open up: 00-functional-component-codealong (PART 2)
Key Objective
Location
starter-code > 01-functional-component-exercise
Timing
10 mins |
|
class Welcome extends React.Component {
render() {
return (
Hello, {this.props.name}
);
}
}
Open up: 02-class-component-codealong
Key Objective
Location
starter-code > 03-class-component-exercise
Timing
10 mins |
|
In programming, composition allows you to build more complex functionality by combining small and focused functions.
this.props
.render()
method, and reference the result instead.ReactDOM.render()
only on parent class.
class Menu extends React.Component {
render() {
return (
);
}
}
class Menu extends React.Component {
constructor(props) {
super(props);
this.items = this.props.menu.map(function(item, index) {
return <li key={index}>{item}</li>
});
}
render() {
return (
);
}
}
OLD SYNTAX
class Menu extends React.Component {
items = this.props.menu.map(function(item, index) {
return <li key={index}>{item}</li>
});
render() {
return (
);
}
}
UPDATED SYNTAX
class App extends React.Component {
render() {
return (
<div className="container">
<Menu menu={this.props.menu} />
<Heading title={this.props.title} />
<Articles articles={this.props.articles} />
<Footer footer={this.props.footer} />
</div>
);
}
}
Open up: 04-composition-codealong
Key Objective
Location
starter-code > 05-composition-exercise
Timing
20 mins |
|
npx create-react-app my-app-name
(Lesson #18)