use-dispatch-promise

0.0.3 • Public • Published

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")

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    2
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i use-dispatch-promise

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

5.76 kB

Total Files

7

Last publish

Collaborators

  • blueish9