Skip to content

Commit a0703a2

Browse files
committed
Day 4
1 parent 1cb1493 commit a0703a2

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

App.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import React from 'react'
2-
import { StyleSheet, Text, View } from 'react-native'
1+
import React, { useState } from 'react'
2+
import { StyleSheet, View } from 'react-native'
33

4-
export default class App extends React.Component {
5-
state = {
6-
counter: 0
7-
}
4+
import Counter from './Counter'
85

9-
render() {
10-
return (
11-
<View style={styles.container}>
12-
<Text style={styles.mainText}>Counter: {this.state.counter}</Text>
13-
</View>
14-
)
15-
}
6+
export default function App() {
7+
const [counter, setCounter] = useState(0)
8+
return (
9+
<View style={styles.container}>
10+
<Counter counter={counter} />
11+
</View>
12+
)
1613
}
1714

1815
const styles = StyleSheet.create({
@@ -21,9 +18,5 @@ const styles = StyleSheet.create({
2118
backgroundColor: '#fff',
2219
alignItems: 'center',
2320
justifyContent: 'center'
24-
},
25-
mainText: {
26-
backgroundColor: '#5CA2FA',
27-
padding: 20
2821
}
2922
})

Counter.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { StyleSheet, Text } from 'react-native'
3+
4+
export default function Counter(props) {
5+
return <Text style={styles.mainText}>Counter:{props.counter}</Text>
6+
}
7+
8+
const styles = StyleSheet.create({
9+
mainText: {
10+
backgroundColor: '#5CA2FA',
11+
padding: 20
12+
}
13+
})

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ You can check the commits to find the part by part codes.
1313
- [Day 1 - React Native Intro](https://www.instagram.com/p/B-EsmshATpS/)
1414
- [Day 2 - Stylesheet in React Native](https://www.instagram.com/p/B-JxJdzlf5E/)
1515
- [Day 3 - State in React Native](https://www.instagram.com/p/B-PK5LmAkKi/)
16+
- [Day 4 - Props in React Native](https://www.instagram.com/p/B-UFIC2gyIl/)

0 commit comments

Comments
 (0)