File tree 8 files changed +36
-17
lines changed
8 files changed +36
-17
lines changed Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import Router from './src/router/Router' ;
3
3
import { Provider } from 'react-redux' ;
4
+ import store from './Store' ;
4
5
5
6
class App extends Component {
6
7
render ( ) {
Original file line number Diff line number Diff line change 1
1
import { createStore , applyMiddleware } from 'redux'
2
- import { rootReducer } from './src/reducers/'
2
+ import rootReducer from './src/reducers/'
3
3
import thunk from 'redux-thunk'
4
4
5
5
const store = createStore (
Original file line number Diff line number Diff line change 19
19
"react-navigation-stack" : " ^1.9.4" ,
20
20
"react-redux" : " ^7.1.1" ,
21
21
"redux" : " ^4.0.4" ,
22
- "redux-logger" : " ^3.0.6"
22
+ "redux-logger" : " ^3.0.6" ,
23
+ "redux-thunk" : " ^2.3.0"
23
24
},
24
25
"devDependencies" : {
25
26
"@babel/core" : " 7.6.4" ,
Original file line number Diff line number Diff line change 1
1
import { FETCH_LIST } from '../common/Types'
2
2
3
- export const fetchList = ( data ) => {
3
+ export const fetchListAction = ( data ) => {
4
4
return {
5
- types : FETCH_LIST ,
5
+ type : FETCH_LIST ,
6
6
payload : {
7
7
data
8
8
}
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import { View , Text } from 'react-native' ;
3
+ import { connect } from 'react-redux' ;
4
+ import { fetchListAction } from '../../actions/ExpenseListActions'
3
5
4
6
class ListExpenses extends Component {
5
7
render ( ) {
8
+ this . props . fetchListAction ( { test :'complete' } )
6
9
return < View > < Text > List Expenses</ Text > </ View >
7
10
}
8
11
}
9
12
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 )
Original file line number Diff line number Diff line change @@ -5,16 +5,11 @@ const initialState = {
5
5
text : '' ,
6
6
}
7
7
8
- const ExpenseListReducer = ( state = initialState , action = { } ) => {
8
+ export default function ExpenseListReducer ( state = initialState , action = { } ) {
9
9
switch ( action . type ) {
10
-
11
10
case FETCH_LIST :
12
- return { ...state , text : action . payload . data }
13
-
11
+ return { ...state , text : action . payload . data }
14
12
default :
15
- return state ;
13
+ return state ;
16
14
}
17
-
18
- }
19
-
20
- export default ExpenseListReducer
15
+ }
Original file line number Diff line number Diff line change
1
+ import { combineReducers } from 'redux'
2
+ import ExpenseListReducer from './ExpenseListReducer'
1
3
2
- import ExpenseListReducer from './expenseListReducer'
3
-
4
- export default rootReducer = combineReducers ( { ExpenseListReducer } )
4
+ const rootReducer = combineReducers ( { expenseList : ExpenseListReducer } )
5
+ export default rootReducer ;
Original file line number Diff line number Diff line change @@ -5474,6 +5474,11 @@ redux-logger@^3.0.6:
5474
5474
dependencies :
5475
5475
deep-diff "^0.3.5"
5476
5476
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
+
5477
5482
redux@^4.0.4 :
5478
5483
version "4.0.4"
5479
5484
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.4.tgz#4ee1aeb164b63d6a1bcc57ae4aa0b6e6fa7a3796"
You can’t perform that action at this time.
0 commit comments