use-dispatch-promise
v0.0.3
Published
with **use-dispatch-promise**, you can dispatch an action and get a promise as return
Downloads
2
Maintainers
Readme
with use-dispatch-promise, you can dispatch an action and get a promise as return
1. Install
yarn add use-dispatch-promise
or
npm install use-dispatch-promise --save
2. Usage
import useDispatchPromise from 'use-dispatch-promise';
const UserProfile = () => {
const [name, setName] = useState();
const dispatch = useDispatchPromise();
useEffect(() => {
(async () => {
const result = await dispatch({ type: FETCH_PROFILE });
setName(result);
})();
}, []);
// return something
};
const FETCH_PROFILE = 'FETCH_PROFILE';
// somewhere in your Redux middleware
action.resolve("Hello world")