[英]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.