Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reuseable DOM with progressive scrolling in Rea...

Avatar for kitson kitson
October 25, 2017

Reuseable DOM with progressive scrolling in React (Belfast JS)

Avatar for kitson

kitson

October 25, 2017

Other Decks in Technology

Transcript

  1. SETTING THE SCENE React is fairly performant out of the

    box Consider rendering large lists of data Each item has a corresponding DOM node including: events, positioning, styling, JS etc... ++ DOM Nodes = -- Browser Performance High rendering times and out-of-memory errors We need a solution to make our web apps more robust with huge lists of data!
  2. VIRTUALIZING THE VIRTUAL DOM All the page DOM, React virtual

    DOM and all components live in memory We want a "Out of sight, out of... DOM" approach
  3. THE SOLUTION 1. We define a fixed viewport for our

    list 2. We only render what is visible to the user 3. We re-use DOM elements (DOM Recycling) REACT-VIRTUALIZED GRID https://github.com/bvaughn/react-virtualized/
  4. DEFINE THE VIEWPORT 1. Define viewport size - 1120px X

    560px 2. Define measurements in local component state 3. Calculate data length values from app state data
  5. THE RENDER() METHOD 1. Define cellRenderer method - computes index,

    grabs the data and renders the components 2. Set Overscan attributes - tweak to avoid lag
  6. LIMITATIONS You must define a fixed viewport size You may

    need to re-calculate on window resize events for responsive layout What about dynamic row heights? [ Demo Part Three ]
  7. REACT-VIRTUALIZED CELL MEASURER High-order component that automatically measures a cell's

    contents by temporarily rendering it in a way that is not visible to the user. Specify a fixed width to measure dynamic height (or vice versa).