Comments (3)
Try to only do this for a top-level component
Notice it says "a" top-level component, not "the" top-level component. You can, and probably should, connect()
multiple times for top-level components (e.g., header, sidebar, main content, footer). You could make the argument that choosing the route handler would be "the" top-level though.
In my opinion, more calls to connect()
doesn't actually make the data harder to trace, but easier. I can see immediately where the data is coming from in a connect()ed
component rather than tracing it up through props.
The downside though, is that it ties a component to a given app, because the component needs to know the shape of the state object. If you don't want to reuse the code though, then that's not really a downside.
It's generally better to have a handful of "smart" components that know about the app, and have them rely on "dumb" components that render entirely from props.
If you're not using it already, look into reselect too. They are about to go 1.0.
You may also be able to take advantage of React's PureRenderMixin
to restrict how deep the re-rendering goes.
from react-redux.
@arkwright I believe you are slightly misinterpreting the point of the the readme where is says
Donβt do this! It kills any performance optimisations because TodoApp will rerender after every action.
The example is showing an connect select function that maps the entire state to the connected component
export default connect(state => state)(TodoApp);
In any application of reasonable size this is likely unnecessary since parts of your state are likely not of concern for the given connected component. The point about performance is recognizing that in this given example the component will be re-rendered anytime any state changes even if it isn't relevant to the connected component.
I think the readme example could probably make this a little more clear so that future readers don't also come away with the impression you did.
Hopefully that helps clear things up.
Thanks,
Josh
from react-redux.
π
from react-redux.
Related Issues (20)
- Add a debug check to `<Provider>` to throw a more detailed error when used in Next HOT 7
- Could not find react-redux context value; please ensure the component is wrapped in a <Provider> HOT 4
- Performance of useSyncExternalStore and React transitions HOT 5
- Disconnect from redux HOT 20
- Check why we no longer bail out of subscription checks when `store.getState()` hasn't changed HOT 1
- Rename `noopCheck` to `identityFunctionCheck` HOT 1
- Color visibility of some note HOT 5
- Unable to resolve module react-dom HOT 10
- Jest: Module import syntax error HOT 9
- Unable to resolve peer dependency react-native on [email protected] HOT 1
- TypeError: dispatcher.useSyncExternalStore is not a function HOT 1
- where development or production mode should be specified? HOT 7
- After some time useSelector stops doing re-renders HOT 8
- Provider properties for dev checks to be passed explicitly to new devModeChecks property HOT 7
- Getting Syntax error for react-redux when building project HOT 4
- Connect not working with detox envinronment HOT 1
- Getting issue in middleware of configureStore when update redux-toolkit to 2.0.1 HOT 1
- useDispatch() causing unexpected navigate back to previous screen HOT 3
- Single global store and two Provider occurs an error for microfrontend app HOT 1
- Test fail with provider in react-native HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-redux.