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

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i use-dispatch-promise

    Weekly Downloads

    1

    Version

    0.0.3

    License

    MIT

    Unpacked Size

    5.76 kB

    Total Files

    7

    Last publish

    Collaborators

    • blueish9