-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
41 lines (37 loc) · 1.02 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { useContext } from 'react'
import { SafeAreaView, Text, StatusBar, TextInput } from 'react-native'
import { ChangeTextController, ChangeTextContext } from './Controller'
let renderCount = 0
const TextArea = () => {
// komponen ini bertindak seperti Consumer
const { text, setText } = useContext(ChangeTextContext)
renderCount++
return (
<React.Fragment>
<Text>Text will appear here: {text}</Text>
<TextInput
style={{ height: 40 }}
placeholder='Type here to translate!'
onChangeText={(text) => setText(text)}
defaultValue={text}
/>
<Text>render Count TextArea : {renderCount}</Text>
</React.Fragment>
)
}
const App = () => {
// komponen ini bertindak seperti Provider
renderCount++
return (
<React.Fragment>
<ChangeTextController>
<StatusBar barStyle='dark-content' backgroundColor='white' />
<SafeAreaView>
<TextArea />
<Text>render count main screen: {renderCount}</Text>
</SafeAreaView>
</ChangeTextController>
</React.Fragment>
)
}
export default App