-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
43 lines (42 loc) · 1.3 KB
/
App.js
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
42
43
import React from 'react';
import { StyleSheet, View, Button } from 'react-native';
import LanguageProvider, { LanguageContext } from './src/languages/LanguageContext';
import Card from './src/components/Card';
export default class App extends React.Component {
changeLanguage = (language, data) => () => {
/**
* Confused? It is just a simple function which returns another function
* I use this pattern to minimize the use of anonymous arrow functions.
* Why? For better performance as they are made on every render.
*/
data.changeLanguage(language);
}
render() {
return (
// Here is our customer Provider
<LanguageProvider>
<View style={styles.container}>
<Card />
<LanguageContext.Consumer>
{/* The Language Consumer which recieves the providers ...state, and changeLanguage. */}
{(data) => {
return (
<Button
title='Change to Spanish'
onPress={this.changeLanguage('spanish', data)}
/>
);
}}
</LanguageContext.Consumer>
</View>
</LanguageProvider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}
});