GithubHelp home page GithubHelp logo

Confusing documentation about react-redux HOT 3 CLOSED

reduxjs avatar reduxjs commented on April 27, 2024
Confusing documentation

from react-redux.

Comments (3)

mindjuice avatar mindjuice commented on April 27, 2024

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.

gnoff avatar gnoff commented on April 27, 2024

@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.

gaearon avatar gaearon commented on April 27, 2024

πŸ‘

from react-redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.