我试图将数组附加到redux商店。
我称之为:
if ($this->loginUser === null && $GLOBALS['TSFE']->loginUser && !empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
// the user is logged in
} else {
// return '' as action content
return '';
}
行动创作者:
var hobbiesChosen = this.props.chosenHobbies;
for ( var i = 0; i < hobbiesChosen.length; i++) {
var hobby = hobbiesChosen[i];
this.props.fetchFilteredHobbies(hobby);
}
我的减速机中有以下内容:
export function fetchFilteredHobbies(hobby) {
return function(dispatch) {
axios.get(`${API_URL}/hobbies/?hobby=${hobby}`, {withCredentials: true})
.then(response => {
dispatch({
type:FILTERED_HOBBIES,
payload: response
});
})
.catch(() => {
console.log("Not working");
});
}
}
过滤的爱好多次运行,每次都会返回一个id列表。
const INITIAL_STATE = { chosen:[]};
export default function(state = INITIAL_STATE, action) {
switch (action.type) {
case FILTERED_HOBBIES:
var filtered = _(action.payload.data).pluck('id').value();
return { chosen: [...state.chosen, filtered] }
基本上,我想将action.payload的id附加到所选的reducer,但我不断收到此错误:
[1,2]
[5]