import { createReducer, createActions } from "reduxsauce";
import Immutable from "seamless-immutable";
import api from "../Services/FixtureApi";
export const INITIAL_STATE = Immutable({
Data1: [],
loadingData: false,
error: null
});
const { Types, Creators } = createActions({
requestData1: null,
receiveData1: null,
failedData1: null
});
export const ExampleTypes = Types;
export default Creators;
export function getData() {
return dispatch => {
dispatch(requestData1());
var promise = new Promise((resolve, reject) => {
const param1 = "";
setTimeout(() => {
resolve(api.getData(param1));
}, 2000);
});
return promise
.then(res => {
dispatch(receiveData1(res.data));
})
.catch(err => {
dispatch(failedData1(err.message));
});
};
}
export const requestData1 = state => ({
...state,
loadingData: true
});
export const receiveData1 = (state, action) => ({
...state,
Data1: [...state.Data1, ...action.payload],
loadingData: false
});
export const failedData1 = (state, action) => ({
...state,
loadingData: false,
error: action.payload
});
export const reducer = createReducer(INITIAL_STATE, {
[Types.REQUEST_DATA1]: requestData1,
[Types.RECEIVE_DATA1]: receiveData1,
[Types.FAILED_DATA1]: failedData1
});
在我的组件中,我
connect
getData
像这样的行动
const mapDispatchToProps = dispatch => ({
fetchData1: () => dispatch(getData())
});
运行此命令会导致以下错误