[英]useDispatch() not work with redux-observable
在我的应用程序中使用useDispatch
hook和async
操作时,我收到以下错误。
错误:操作必须是普通对象。 使用自定义中间件进行异步操作。
......任何解决方案?
//my component >>>
const Comp: React.FC<any> = (props) => {
const dispatch = useDispatch();
const subscribers = useSelector((state: any) => state.subscribers.subscribers)
return (
<div>
<h3>Alo Brasil</h3>
<button onClick=
{()=>dispatch(SubscribersTypes.GET_ALL_SUBSCRIBERS_START)}>Get All</button>
</div>
)
}
//my store >>>
const epicMiddleware = createEpicMiddleware();
const composeEnhancers = composeWithDevTools({});
const configureStore = (preloadedState: ApplicationState) =>
createStore(
AppReducer,
preloadedState,
composeEnhancers(
applyMiddleware(
epicMiddleware
)
)
);
const store = configureStore(initialStateApp);
epicMiddleware.run(AppEpic)
//my epic>>
const getAllSubscribersEpic = (action$: any) =>
action$.pipe(
filter(isActionOf(actions.getAllRequestStart)),
switchMap(() =>
from(axios.get(url))
.pipe(
map((response: AxiosResponse) => response.data),
map((data: Array<Subscriber>) => actions.getAllRequestFinish(data)),
catchError(error => of(actions.subscribersError(error)))
)
)
)
好吧,我的代码中出现了错误...我已经在我的史诗中添加了类型,现在它可以工作了,如果有人经历这个,我会留下答案。
type Action = ActionType<typeof actions>;
const getAllEventsEpic : Epic<Action, Action, ApplicationState>= (action$) =>
action$.pipe(
...
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.