4 ms·
> What kinds of problems did you see? A unique action generator, action type, and reducer for every endpoint is the common failure mode (probably because thats
by kansface 7y ago
> What kinds of problems did you see?
A unique action generator, action type, and reducer for every endpoint is the common failure mode (probably because thats what the docs do). Also, the react-redux bindings are a truly horrific API - only call connect where you absolutely must (you can can actually call dispatch on the store if you have a reference).
- acemarke 7y agoWhy do you feel that React-Redux has a "horrific API"? You might want to read my "History and Implementation of React-Redux" post [0] to understand why `connect` is written the way it is, as well as watch my recent talk "A Deep Dive into React-Redux" [1]. FWIW, we do now have a hooks-based API as well [2]. Do you feel that looks any better? In general, we recommending connecting _more_ components for better performance [3], and recommend _against_ importing the store directly [4]. [0] https://blog.isquaredsoftware.com/2018/11/react-redux-history-implementation/ https://blog.isquaredsoftware.com/2018/11/react-redux-histor... [1] https://blog.isquaredsoftware.com/2019/07/blogged-answers-thoughts-on-hooks/ https://blog.isquaredsoftware.com/2019/07/blogged-answers-th... [2] https://react-redux.js.org/api/hooks https://react-redux.js.org/api/hooks [3] https://redux.js.org/faq/react-redux#should-i-only-connect-my-top-component-or-can-i-connect-multiple-components-in-my-tree https://redux.js.org/faq/react-redux#should-i-only-connect-m... [4] https://redux.js.org/faq/store-setup#can-or-should-i-create-multiple-stores-can-i-import-my-store-directly-and-use-it-in-components-myself https://redux.js.org/faq/store-setup#can-or-should-i-create-...
- wilsonrocks 7y agoI find connect quite verbose for a simple 'I want this component to be able to access the userName field' use case. However the hooks api is excellent for this. You can also write custom hooks that pull data from redux and other sources (in my case, root level props passed from another(angular) app, that I made available using Context.
- kansface 7y ago> Why do you feel that React-Redux has a "horrific API"? `connect()` is a function that takes 4 optional arguments. The first one is a function, the second is an obj or a function that returns an object, the third is a function that takes 3 arguments that returns an object, the last is an options object that takes up to 7 params (four of which are functions)! Unfortunately, you aren't done yet, because connect returns a function! You pass your new function a component and it returns a different one. Now, you have something you can use! That is the most complicated interface I've ever seen in any library. `connect` makes code much harder to understand for what seems to be a simple task - wire some data into a component when the data changes. > Do you feel that looks any better? Yeah!