Make a react-window (1)

 

Introduction

if your DOM is to much that slow dow your render performance, most of case will happend on the table element, we had react-window could help us resolve this issue

react-window

https://miro.medium.com/max/1400/1*e1YBmF_MtZCI1Y1lYCrSVA.png

FixedList we have to give it parameter:

  • height : scroll list height
  • itemcount : row arrary length
  • itemSize: row height
  • width: scroll list width

actually it already resolve to much DOM problem , but I want dig more deep tech that I could understand how it work and I could did more flexible design DOM no need rely the plugin

Let see the detail:

https://miro.medium.com/max/1400/1*RkG2sXM6FgBmaGxwJk1fpw.png

how parameter work:

  • firsrt div: height is for first div make ****max-height and we also give it the overflow properties
  • second div: height ****is itemcount * itemSize that we could render the scroll
  • row div: we are use absoulte and give it index * itemSize = top Height

https://miro.medium.com/max/1400/1*k3KDpQ5S3XNAHgEF1cPNTw.gif

when we are scrolling that you can find it will change :

  • row top height
  • replace the DOM tree

the row DOM won’t be increase or decrease , it’s seem like is use arrary function slice to accomplish replace

Survey Result

I think it is use IntersectionObserver function to accomplish virtual scrolling , it could help you watch the element and it is Intersecting that will trigger fucntional do somthing , so next artical I will show you how did I do the simliar component as like react-window

留言

這個網誌中的熱門文章

Vue那些我踩過的坑(Vuex-TypeScript)

Vue(Vue3取代 Vuex?)

前端優化效能-1(lazy-img)