Skip to content

Instantly share code, notes, and snippets.

@chuyihuang
Created August 13, 2017 16:35
Show Gist options
  • Save chuyihuang/06d6cd4e4ea4e16230e0d33c5104fa4a to your computer and use it in GitHub Desktop.
Save chuyihuang/06d6cd4e4ea4e16230e0d33c5104fa4a to your computer and use it in GitHub Desktop.
React Native workshop #2 snippet
import React, { Component } from 'react';
import { View, TextInput, Text } from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
value: null
}
}
render() {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<TextInput
style={{width: '80%', fontSize: 24}}
value={this.state.value}
onChangeText={(value) => this.setState({value})}
/>
<Child text={this.state.value} />
</View>
);
}
}
class Child extends Component {
componentWillReceiveProps() {
console.log("component will receive props");
}
shouldComponentUpdate() {
console.log("should component update");
return false;
}
componentWillUpdate() {
console.log("component will update");
}
componentDidUpdate() {
console.log("component did update");
}
render() {
return (
<View>
<Text>{this.props.text}</Text>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment