質問編集履歴
1
ご提示いただいたコードにあわせて変更を行いました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,3 +7,91 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
お手数ですがご教示をお願いいたします。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
補足:
|
14
|
+
|
15
|
+
[containers/mainContainer.js](https://github.com/amine-benselim/wp-react-redux/blob/master/src/containers/mainContainer.js)
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
const mapDispatchToProps = dispatch => {
|
20
|
+
|
21
|
+
return {
|
22
|
+
|
23
|
+
getPosts: (postType, page) => {
|
24
|
+
|
25
|
+
dispatch(getPosts(postType, page)).then(response => {
|
26
|
+
|
27
|
+
if (!response.error) {
|
28
|
+
|
29
|
+
let newPosts = posts.concat(response.payload.data);
|
30
|
+
|
31
|
+
dispatch(
|
32
|
+
|
33
|
+
getPostsSuccess(
|
34
|
+
|
35
|
+
newPosts,
|
36
|
+
|
37
|
+
+response.payload.headers["x-wp-totalpages"]
|
38
|
+
|
39
|
+
)
|
40
|
+
|
41
|
+
);
|
42
|
+
|
43
|
+
} else {
|
44
|
+
|
45
|
+
dispatch(getPostsFailure(response.payload.data));
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
});
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
};
|
54
|
+
|
55
|
+
};
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
[actions/actionCreators.js](https://github.com/amine-benselim/wp-react-redux/blob/master/src/actions/actionCreators.js)
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
export function getPosts(postType = "posts", page = 1) {
|
66
|
+
|
67
|
+
const request = axios.get(
|
68
|
+
|
69
|
+
`/wp-json/wp/v2/${postType}?context=embed&per_page=4&page=${page}`
|
70
|
+
|
71
|
+
);
|
72
|
+
|
73
|
+
return {
|
74
|
+
|
75
|
+
type: actionTypes.GET_POSTS,
|
76
|
+
|
77
|
+
payload: request
|
78
|
+
|
79
|
+
};
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
のように対応したところ、
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
`Unhandled Rejection (TypeError): Cannot read property 'message' of undefined`
|
92
|
+
|
93
|
+
./src/reducers/reducer_main.js
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
とのエラーが出ました。
|