我是反应原生的新手,我有点被困在redux中。我正在尝试从api端点获取车辆,我正在使用redux-saga,发送请求,成功获取数据并调度FETCH_VEHICLE_SUCCESS操作。和状态在redux商店中更新。但在此之后,自动触发一个动作(如下图所示的REDUX_STORAGE_SAVE)并清空状态即车辆(参见下图)。为什么会这样?
我正在使用redux-logger进行记录,如下图所示,车辆对象变空。
saga.js
function fetchVehicleCall() {
console.log('here');
return new Promise((resolve, reject) => {
RegisterHelper.fetchAllVehicles()
.then(res => {
console.log('now');
resolve(res);
})
.catch(err => reject(err));
});
}
function* fetchVehicleRequest() {
while (true) {
yield take(GET_VEHICLE_REQUEST);
try {
const response = yield call(fetchVehicleCall);
yield put(fetchVehicleSuccess(response));
console.log('SAGA FETCH SUCCESS: ', response);
} catch (err) {
console.log('SAGA FETCH ERR: ', err);
}
}
}
export default function* root() {
yield fork(fetchVehicleRequest);
}
actions.js
export function fetchVehicleSuccess(vehicles) {
return {
type: FETCH_VEHICLE_SUCCESS,
vehicles,
};
}
reducer.js
case FETCH_VEHICLE_SUCCESS:
return Object.assign({}, state, {
vehicles: action.vehicles,
});