Is using getState in a Redux Thunk good practice?

后端 未结 1 1952
忘了有多久
忘了有多久 2021-02-05 01:59

I have seen conflicting (or just confusing, to me) answers in other questions here regarding whether using getState within an action is acceptable, or not, and I ha

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 02:36

    I wrote an extended blog post called Idiomatic Redux: Thoughts on Thunks, Sagas, Abstraction, and Reusability, which addresses this topic in detail. In it, I respond to several critiques of thunks and use of getState (including Dan Abramov's comments in Accessing Redux state in an action creator?). In fact, my post was specifically inspired by questions like yours.

    As a TL;DR of my post: I believe that thunks are a completely viable tool for use in Redux applications, and encourage their use. While there are some valid concerns to be aware of when using thunks and sagas, and using getState/select inside of them, these concerns should not scare you away from using thunks.

    0 讨论(0)
提交回复
热议问题