Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit ce020c9

Browse files
author
Sarah Emerson
committed
Use payload and destructure the action
1 parent 6eacae5 commit ce020c9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

client/actions/index.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import { getFruits } from '../apis/fruits'
22

33
export const SET_FRUITS = 'SET_FRUITS'
44

5-
export function setFruits (fruits) {
5+
export function setFruits(fruits) {
66
return {
77
type: SET_FRUITS,
8-
fruits
8+
payload: fruits,
99
}
1010
}
1111

12-
export function fetchFruits () {
13-
return dispatch => {
14-
return getFruits()
15-
.then(fruits => {
16-
dispatch(setFruits(fruits))
17-
return null
18-
})
12+
export function fetchFruits() {
13+
return (dispatch) => {
14+
return getFruits().then((fruits) => {
15+
dispatch(setFruits(fruits))
16+
return null
17+
})
1918
}
2019
}

client/reducers/fruits.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { SET_FRUITS } from '../actions'
33
const initialState = []
44

55
const reducer = (state = initialState, action) => {
6-
switch (action.type) {
6+
const { type, payload } = action
7+
switch (type) {
78
case SET_FRUITS:
8-
return action.fruits
9+
return payload
910
default:
1011
return state
1112
}

0 commit comments

Comments
 (0)