GithubHelp home page GithubHelp logo

rokasmik / optimize-react-redux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gaearon/todos

0.0 0.0 0.0 744 KB

Optimizing rendering performance with react-redux

JavaScript 87.90% CSS 12.10%

optimize-react-redux's Introduction

optimize-react-redux

Presentation about optimizing rendering performance with react-redux

Overview of tools technics used for connection of react & redux

  • react-redux API
  • react-redux bad practices
  • react-redux good practices
  • memoization, getters & selectors

Example of optimization

npm run start -> localhost:9000

The app contains two paths with two differently rendered lists. To change the list, go to components/App.js and

1st list: import ItemsList from '../containers/items';

2nd list: import ItemsList from '../containers/items-list';

First list:

  • Rendered with one container connected to the store
  • Gets items details in props

Second list:

  • Rendered with two containers connected to the store
  • First containers connects only a list of items ids
  • Second container renders one item, taking it's data by the id from the store

A huge list is connected to be able to see the rendering optimization difference.

The flow of events after a "love" action:

One container list:

  1. Container recalculates mapStateToProps
  2. Container rerenders the connected component as the props changes
  3. React reconcilation triggers for every component in the list, checking if the components needs to be updated (in this case, an expensive operation)
  4. One of the components is updated

Two containers list:

  1. List container recalculates mapStateToProps
  2. List does not change as ids did not change. React list component is not rerendered
  3. Each item container recalculates mapStateToProps with shallow equal
  4. One of the container rerenders because props changes, only one react component rerenders

Results:

One container list:

Screenshot

Two containers list:

Screenshot

To do:

  • Dive in to reconsilation, maybe instead of live examples with per instance memoization

optimize-react-redux's People

Contributors

gaearon avatar rokasmik avatar

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.