通过实用程序(RTK-Query)派遣商店操作
我目前正在将我们的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,您只需在需要它的文件中导入
store
并调用store.dispatch
- 您只是不应该在React组件中这样做。Sure, you can just import
store
in the file where you need it and callstore.dispatch
- you just should not be doing that in React components.