September 2018
Intermediate to advanced
302 pages
7h 17m
English
Button is such a common component that you will find yourself using it in any kind of app. Let's build a small like counter with up and down buttons:
// Chapter 2 / Example 7 / src / LikeCounter.jsclass LikeCounter extends React.Component { state = { likeCount: 0 } // like/unlike function to increase/decrease like count in state like = () => this.setState({likeCount: this.state.likeCount + 1}) unlike = () => this.setState({likeCount: this.state.likeCount - 1}) render = () => ( <View style={styles.container}> <Button onPress={this.unlike} title="Unlike" /> <Text style={styles.text}>{this.state.likeCount}</Text> <Button onPress={this.like} title="Like" /> </View> );}// Styles omitted for clarity
Further modifications to ...
Read now
Unlock full access