-
Notifications
You must be signed in to change notification settings - Fork 43
/
App.js
56 lines (50 loc) · 1.34 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
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { Component } from "react";
import {
View,
Text,
StyleSheet,
TouchableOpacity
} from "react-native";
import { createStore } from 'redux'
import CounterApp from './src/CounterApp'
import { Provider } from 'react-redux'
/**
* Store - holds our state - THERE IS ONLY ONE STATE
* Action - State can be modified using actions - SIMPLE OBJECTS
* Dispatcher - Action needs to be sent by someone - known as dispatching an action
* Reducer - receives the action and modifies the state to give us a new state
* - pure functions
* - only mandatory argument is the 'type'
* Subscriber - listens for state change to update the ui
*/
const initialState = {
counter: 0
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'INCREASE_COUNTER':
return { counter: state.counter + 1 }
case 'DECREASE_COUNTER':
return { counter: state.counter - 1 }
}
return state
}
const store = createStore(reducer)
class App extends Component {
render() {
return (
<Provider store={store}>
<CounterApp />
</Provider>
);
}
}
export default App
// export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}
});