How to provide a history instance to a saga?

☆樱花仙子☆ 提交于 2019-12-04 09:16:33

As you pointed out, making history directly available as a singleton is one option. Another similar (if not controversial) approach is to add history to the redux state. So in your saga, you'd use a select effect to get the history instance.

Both approaches effectively treat history as singletons, but by storing it into the redux state, you can mock the history object a bit easier in unit tests. What I mean by easier is that you can employ the same technique to mock the history object as mocking any other object in the redux state.

Also, you would presumably instantiate the history object along with other initial state so your logic to initialize history wouldn't be a one off exception as to how application state is initialized.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!