Professional Documents
Culture Documents
James Landay
Santiago Gutierrez
Abdallah AbuHashem
https://cs47si.stanford.edu
● Name
● Gender
● Height
● Weight
● Hair Color
● Eye Color
● Picture?
...
How do I make my app respond to changes?
(e.g. a button click, network request fetch, etc)
Component API
State and Props
Component API
State and Props
Props
The properties passed to the constructor of a component are called props.
<Image
source={{uri: "https://facebook.github.io/react-native/docs/assets/favicon.png"}}
/>
Component API
Props
<Image
source={{uri: "https://facebook.github.io/react-native/docs/assets/favicon.png"}}
/>
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
Component API
Props
render() {
return (
<Image
source={{uri: "
https://facebook.github.io/react-native/docs/assets/favicon.png"}}
/>
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
);
Parents can pass props down to children. Not the other way around.
Component API
Props
constructor(props) {
super(props);
Component API
Props
Component API
State and Props
Props
The properties passed to the constructor of a component are called props.
State
An object with details about how a Component should render.
Component API
State and Props
Props
The properties passed to the constructor of a component are called props.
State
An object with details about how a Component should render.
render() {
return (
<View style={styles.container}>
<Text>Hello World!</Text>
</View>
);
}
}
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
state = {
headline: 'Welcome to my app!'
}
render() {
return (
<View style={styles.container}>
<Text>Hello World!</Text>
</View>
);
}
}
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
state = {
headline: 'Welcome to my app!'
}
render() {
return (
<View style={styles.container}>
<Text>{this.state.headline}</Text>
</View>
);
}
}
Live Demo
Jedi ID Card
OH Today (3PM-5PM @
Lathrop)
CS47SI: Cross-Platform Mobile Development
Lecture 2B: Creating and Controlling Components
James Landay
Santiago Gutierrez
Abdallah AbuHashem
https://cs47si.stanford.edu