通过实用程序(RTK-Query)派遣商店操作

发布于 2025-01-25 14:58:30 字数 318 浏览 2 评论 0原文

我目前正在将我们的Websocket引擎实施到我们的Redux-Toolkit商店。我们的Websocket连接/重新连接&事件处理逻辑保存在其自己的实用程序文件中,因为每个RTK Query Endpoint都使用相同的Websocket,并将单个处理程序传递给UTIL文件。

对于我们的目的而言,这非常有效,但是一旦open> open close> close& 错误事件触发,用于在整个应用程序中显示加载状态。

可以触发商店调度事件而无需使用uderIspatch挂钩吗?

I am currently implementing our websocket engine to our Redux-Toolkit store. Our websocket connection/reconnect & event handling logic is held in it's own utility file, because each RTK-Query endpoint uses the same websocket, and passes individual handlers to the util file.

This works quite nicely for our purposes, but I would also like to set the websocket connection state in store once the open close & error events trigger, for displaying loading states throughout the App.

Is it possible to trigger store dispatch events without using the useDispatch hook?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携君以终年 2025-02-01 14:58:30

当然,您只需在需要它的文件中导入store并调用store.dispatch - 您只是不应该在React组件中这样做。

Sure, you can just import store in the file where you need it and call store.dispatch - you just should not be doing that in React components.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文