redux-promise-async-actions
v1.0.0
Published
redux-promise-async-actions
Downloads
4
Maintainers
Readme
redux-promise-async-actions
使用
import promiseAsyncMiddleware from 'redux-promise-async-actions';
与 redux-actions 一起使用
支持 FSA actions, 你可以和 redux-actions 一起使用
Async action creators
createAction('FETCH_THING', async id => {
const result = await somePromise;
return result.someValue;
});
createAction('FETCH_THING', async id => {
const result = await somePromise;
return (dispatch, getState) => {
dispatch(someData);
dispatch(someData2);
return result.someValue;
};
});
createAction('FETCH_THING', id => {
return (dispatch, getState) => {
dispatch(someData);
dispatch(someData2);
return result.someValue;
};
});
与网络请求一起使用API
import { WebAPI } from '../utils/WebAPI';
export const getThing = createAction('GET_THING', WebAPI.getThing);
export const getThing = createAction('GET_THING', async (id)=>{
const data = await WebAPI.getThing();
return data.result;
});
export const createThing = createAction('POST_THING', WebAPI.createThing);
export const updateThing = createAction('UPDATE_THING', WebAPI.updateThing);
export const deleteThing = createAction('DELETE_THING', WebAPI.deleteThing);