Professional Documents
Culture Documents
Lezione03 Intro A React PDF
Lezione03 Intro A React PDF
Components
Component composition
Challenges
What is React
“A JavaScript library for building User Interface”
Features:
Declarative (vs imperative)
Component based
Library for the View layer (as part of a full MVC framework)
can be used with any other libraries
doesn’t provide out-of-the box data management, server
communication, routing, etc
very popular for Web Development (React.js)
What is React Native
A framework that uses the React library to render native
(mobile) components. Ex:
• <Text> renders UILabel (on iOS) and
Android.widget.TextView (on Android)
• <View> renders UIView (on iOS) and Android.view.View (on
Android
• <Image> renders UIImageView (on iOS) and
Android.widget.ImageView (on Android)
React.js vs React Native hello World
https://facebook.github.io/react-native/docs/props.html
• Strings can passed directly, for other data types use curly braces {} to wrap the
values.
• Boolean values can be simplified with just the property name (presence = true,
absence = false), like in HTML
<Title
text="Hello World!"
highlighted
fontSize={24}
/>
Variable declaration
Variable scopes:
• JavaScript (ES5)
• global scope / function scope
• var to define a variable
block-scoped
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
// will print 7
console.log('my favorite number is: ' + MY_FAV);
Arrow functions (ES2015)
Shorter syntax for function expressions
handy to define “one-line” function when there is only 1 statement (can omit parenthesis
too)
const sum = (a, b) => a + b;
sum(3,5);
nomeCompleto("Mario", "Rossi");
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/
Arrow_functions
Questions
Challenges
Geek:
• build a <Card> component that takes in two props (title
and image); images are local
• renders 3 Cards with your preferred programming
languages
Nerd:
• renders more that 3 Cards enabling scrolling; images are
remote
Hacker:
• renders a list of Cards taken from an array