Skip to content

Commit 7ca802f

Browse files
committed
Reducer setup complete
1 parent babcd18 commit 7ca802f

File tree

8 files changed

+36
-17
lines changed

8 files changed

+36
-17
lines changed

App.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {Component} from 'react';
22
import Router from './src/router/Router';
33
import {Provider} from 'react-redux';
4+
import store from './Store';
45

56
class App extends Component {
67
render() {

Store.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createStore, applyMiddleware } from 'redux'
2-
import { rootReducer } from './src/reducers/'
2+
import rootReducer from './src/reducers/'
33
import thunk from 'redux-thunk'
44

55
const store = createStore(

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"react-navigation-stack": "^1.9.4",
2020
"react-redux": "^7.1.1",
2121
"redux": "^4.0.4",
22-
"redux-logger": "^3.0.6"
22+
"redux-logger": "^3.0.6",
23+
"redux-thunk": "^2.3.0"
2324
},
2425
"devDependencies": {
2526
"@babel/core": "7.6.4",

src/actions/ExpenseListActions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { FETCH_LIST } from '../common/Types'
22

3-
export const fetchList = (data) => {
3+
export const fetchListAction = (data) => {
44
return {
5-
types: FETCH_LIST,
5+
type: FETCH_LIST,
66
payload: {
77
data
88
}
+17-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
import React, { Component } from 'react';
22
import { View, Text } from 'react-native';
3+
import { connect } from 'react-redux';
4+
import { fetchListAction } from '../../actions/ExpenseListActions'
35

46
class ListExpenses extends Component {
57
render(){
8+
this.props.fetchListAction({test:'complete'})
69
return <View><Text>List Expenses</Text></View>
710
}
811
}
912

10-
export default ListExpenses
13+
/**
14+
* Maps properties from redux store
15+
* to state in a component
16+
* @param {object} state
17+
* @returns
18+
*/
19+
mapStateToProps = state => {
20+
console.log('state ', state)
21+
return {
22+
state
23+
}
24+
}
25+
26+
export default connect(mapStateToProps, {fetchListAction})(ListExpenses)

src/reducers/ExpenseListReducer.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ const initialState = {
55
text: '',
66
}
77

8-
const ExpenseListReducer = (state = initialState, action = {}) => {
8+
export default function ExpenseListReducer(state = initialState, action = {}){
99
switch(action.type) {
10-
1110
case FETCH_LIST:
12-
return { ...state, text: action.payload.data }
13-
11+
return { ...state, text: action.payload.data }
1412
default:
15-
return state;
13+
return state;
1614
}
17-
18-
}
19-
20-
export default ExpenseListReducer
15+
}

src/reducers/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
import { combineReducers } from 'redux'
2+
import ExpenseListReducer from './ExpenseListReducer'
13

2-
import ExpenseListReducer from './expenseListReducer'
3-
4-
export default rootReducer = combineReducers ({ ExpenseListReducer })
4+
const rootReducer = combineReducers ({ expenseList: ExpenseListReducer })
5+
export default rootReducer;

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -5474,6 +5474,11 @@ redux-logger@^3.0.6:
54745474
dependencies:
54755475
deep-diff "^0.3.5"
54765476

5477+
redux-thunk@^2.3.0:
5478+
version "2.3.0"
5479+
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
5480+
integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==
5481+
54775482
redux@^4.0.4:
54785483
version "4.0.4"
54795484
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.4.tgz#4ee1aeb164b63d6a1bcc57ae4aa0b6e6fa7a3796"

0 commit comments

Comments
 (0)