piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 98 forks source link

react-redux hooks #181

Closed ghost closed 5 years ago

ghost commented 5 years ago

redux-observable

actions

import { createAsyncAction } from 'typesafe-actions';

export const fetchNavBarAsync = createAsyncAction(
  'FETCH_NAVBAR_LIST_REQUEST',
  'FETCH_NAVBAR_LIST_SUCCESS',
  'FETCH_NAVBAR_LIST_FAILURE',
  'FETCH_NAVBAR_LIST_CANCEL'
)<string, any[], Error, string>();
import { useSelector, useDispatch } from 'react-redux';

  const dispatch = useDispatch();
 dispatch(fetchNavBarAsync.request);

How can I use it react hooks

hsz commented 5 years ago

Try with

dispatch(fetchNavBarAsync.request('foo'));
ghost commented 5 years ago

Thank you