3 ms·
Yes, I'm familiar with the arguments against it, but my experience using Redux has led me to strongly disagree with them. I don't think the proposed benefits ha
by bfrydl 8y ago
Yes, I'm familiar with the arguments against it, but my experience using Redux has led me to strongly disagree with them. I don't think the proposed benefits have much value in actual practice, and limiting the use of dispatch to plain objects makes state logic easier to understand in my opinion.
Also, I think my primary issue with redux-thunk isn't that you dispatch a non-object but that the getState argument encourages async operations which are dependent on the current store state, possibly its current state at multiple different points of time. Personally I think that as much as possible async operations should be written to use only parameters as input and dispatch actions as output.
Plus I use TypeScript where things like this getState argument are really annoying for strong typing. You need to import the type of your store or store state in every file that uses a thunk.
I also personally think that the extra ceremony applied to Redux is a contributor to the difficulty new developers have understanding it, because they believe that Redux does more than it actually does.
- acemarke 8y agoI understand most of your concerns, and it seems like we'll have to agree to disagree to some extent. FWIW, I specifically addressed several concerns regarding use of `getState` in my post "Idiomatic Redux: Thoughts on Thunks, Sagas, Abstraction, and Reusability" [0]. I agree that trying to fully capture the potentially dynamic behavior with static types can be painfully difficult. I don't actually use TS myself, yet, but we've definitely had lots of issues pop up related to this (such as [1] ), and I think I get the general issues involved. Unfortunately, I don't have any real suggestions to offer on this front, both because my TS knowledge is limited to "declare types for function params and object fields", and because I'm not sure there _are_ ways around that. Having said that, our new Redux Starter Kit package [2] is specifically intended to help simplify a number of common Redux use cases, and I'd encourage anyone using Redux to try it out. Long-term, we plan to revamp the Redux docs content [3], and I hope to improve a lot of the teaching workflow. I also hope to make RSK the "default" way to use Redux for most people. [0] https://blog.isquaredsoftware.com/2017/01/idiomatic-redux-thoughts-on-thunks-sagas-abstraction-and-reusability/ https://blog.isquaredsoftware.com/2017/01/idiomatic-redux-th... [1] https://github.com/reduxjs/redux-thunk/issues/231 https://github.com/reduxjs/redux-thunk/issues/231 [2] https://redux-starter-kit.js.org https://redux-starter-kit.js.org [3] https://github.com/reduxjs/redux/issues/3313 https://github.com/reduxjs/redux/issues/3313
- bfrydl 8y agoI do think we need to agree to disagree. That being said according to the README for the Redux Starter Kit these are listed as problems it wants to solve: • "Configuring a Redux store is too complicated" • "I have to add a lot of packages to get Redux to do anything useful" • "Redux requires too much boilerplate code" I can't help but point out that all of these concerns can also be solved by not using any extra libraries and just doing what I suggested. Configuration: createStore() Lot of packages: Not needed, just pass dispatch around. Boilerplate code: Pretty much just combineReducers calls.
- acemarke 8y agoI'd encourage you to read through the RSK docs further to see what all it actually does, then :)
- bfrydl 8y agoSorry, I know you're heavily involved in this ecosystem, I just don't really see the need for any of this. create-react-app is mostly about webpack, isn't it? Redux works fine on its own.
- acemarke 8y agoFWIW, I'm a Redux maintainer, and I built this specifically in response to how I've seen people _want_ to use Redux, and the concerns they've raised about using Redux. [0] Almost everyone uses `redux-thunk` [1]. Adding that to a plain Redux store takes a few steps. Adding middleware _and_ setting up the Redux DevTools Extension adds another couple steps [2] So, RSK's `configureStore()` does that by default [3]. Accidental mutation is the #1 mistake folks make when writing Redux apps [4]. So, `configureStore()` adds a middleware by default that warns about that mistake [5]. Writing immutable update logic can be difficult, and especially painful if the updates are nested [6]. Also, many folks don't want to use switch statements for some reason [7]. So, we ship a `createReducer()` utility that lets you write "mutative" immutable updates, and define the reducers as a lookup table [8]. Many people don't like writing action types and action creators by hand. So, RSK includes a `createSlice` utility that generates those automatically. [9] None of these are incredibly ground-breaking. There's lots of existing Redux addons that do similar things. But, we're including all these utilities in an "official" package, and recommending that folks use it. No one's being forced to use RSK. But, I can say that just about everyone who's seen this has said something similar to "this looks awesome, I can't wait to use this!". [0] https://github.com/reduxjs/redux/issues/2295 https://github.com/reduxjs/redux/issues/2295 [1] https://blog.isquaredsoftware.com/presentations/2017-09-might-need-redux-ecosystem/#/37 https://blog.isquaredsoftware.com/presentations/2017-09-migh... [2] https://redux.js.org/recipes/configuring-your-store#integrating-the-devtools-extension https://redux.js.org/recipes/configuring-your-store#integrat... [3] https://redux-starter-kit.js.org/api/configureStore https://redux-starter-kit.js.org/api/configureStore [4] https://redux.js.org/faq/react-redux#why-isnt-my-component-re-rendering-or-my-mapstatetoprops-running\ https://redux.js.org/faq/react-redux#why-isnt-my-component-r... [5] https://redux-starter-kit.js.org/api/getDefaultMiddleware https://redux-starter-kit.js.org/api/getDefaultMiddleware [6] https://redux.js.org/recipes/structuring-reducers/immutable-update-patterns https://redux.js.org/recipes/structuring-reducers/immutable-... [7] https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-2/#switch-statements https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-ta... [8] https://redux-starter-kit.js.org/api/createReducer https://redux-starter-kit.js.org/api/createReducer [9] https://redux-starter-kit.js.org/api/createSlice https://redux-starter-kit.js.org/api/createSlice