4 ms·
There are two ways to make them more loosely coupled: 1. declare your connect's in a separate file that import your component and live alongside your container
by nikcub 10y ago
There are two ways to make them more loosely coupled:
1. declare your connect's in a separate file that import your component and live alongside your containers, actions, reducers, etc.
2. write your own connect HOC that brings in redux. If you read the connect source[0] you'll find that it is actually really simple at it's core - but it is over complicated by having to account for so many use cases - your own HOC could/should be ~30 lines
I now use 2. because it produces proper separation and makes it easy to swap out components later on (or use more than one).
[0] https://github.com/reactjs/react-redux/blob/master/src/connect/connect.js https://github.com/reactjs/react-redux/blob/master/src/conne...