Gathering detailed insights and metrics for react-render-if-visible
Gathering detailed insights and metrics for react-render-if-visible
Gathering detailed insights and metrics for react-render-if-visible
Gathering detailed insights and metrics for react-render-if-visible
Harness the power of Intersection Observers for simple list virtualization in React
npm install react-render-if-visible
Typescript
Module System
Min. Node Version
Node Version
NPM Version
87.7
Supply Chain
92.3
Quality
75.4
Maintenance
100
Vulnerability
100
License
TypeScript (90.6%)
JavaScript (9.4%)
Total Downloads
2,713,170
Last Day
3,287
Last Week
17,062
Last Month
74,019
Last Year
1,325,414
Apache-2.0 License
139 Stars
28 Commits
24 Forks
2 Watchers
5 Branches
4 Contributors
Updated on Apr 25, 2025
Minified
Minified + Gzipped
Latest Version
2.1.1
Package Id
react-render-if-visible@2.1.1
Unpacked Size
27.52 kB
Size
9.13 kB
File Count
7
NPM Version
6.14.15
Node Version
14.18.1
Cumulative downloads
Total Downloads
Last Day
33%
3,287
Compared to previous day
Last Week
12.7%
17,062
Compared to previous week
Last Month
-14.6%
74,019
Compared to previous month
Last Year
37.6%
1,325,414
Compared to previous year
Harness the power of Intersection Observers for simple list virtualization in React.
This tiny React component is a drop-in list virtualization alternative that defers rendering of its children until it is on or near the screen. Unlike other virtualization libraries, it takes about one minute to integrate and doesn't require you to change your code other than wrapping each item in <RenderIfVisible></RenderIfVisible>
.
It works equally well with responsive item heights, responsive grids, non-flat lists, and any other HTML that would normally make other virtualization libraries complicated to implement.
Advantages over other virtualization techniques:
<RenderIfVisible></RenderIfVisible>
overflow: scroll
)This solution has been used successfully in production on NightCafe Creator for almost 2 years.
Read more about the background and development of this component on dev.to.
In v1.x, the component detected when it was being rendered on the server, and set the initial visible state to true. To work with server-side rendering in React 17+, we no-longer detect the server from within the component, but a new prop initialVisible
is exposed which allows you to control whether the child component should be visible on first render or not. This is intended to be used for things like always rendering the first N components as visible, and the rest as not visible (until they're scrolled into view).
stayRendered
(thanks to cyremur) that will keep the element visible after it's been rendered for the first timeFirst, install the component from npm.
1npm install react-render-if-visible --save
Then, import the component and wrap each child with it.
1import React from 'react' 2import RenderIfVisible from 'react-render-if-visible' 3import MyListItem from './list-item' 4 5const ESTIMATED_ITEM_HEIGHT = 200 6 7export const MyItemList = (items) => ( 8 <div className="my-list"> 9 {items.map(item => ( 10 <RenderIfVisible defaultHeight={ESTIMATED_ITEM_HEIGHT}> 11 <MyListItem item={item} /> 12 </RenderIfVisible> 13 ))} 14 </div> 15)
defaultHeight?: number
Default: 300 - An estimate of the element's height.visibleOffset?: number
Default: 1000 - How far outside the viewport (or root
element) in pixels should elements be considered visible?stayRendered?: boolean
Default: false - Should the element stay rendered after it becomes visible?root?: HTMLElement
Default: null - Root element passed to IntersectionObserver
.rootElement?: HTMLElement
Default: "div" - This is the HTML element that will wrap around the children and placeholder. This root element is always present.placeholderElement?: HTMLElement
Default: "div" - This is the HTML element that will be used for the placeholder. This placeholder element is contained in the root element.children: React.ReactNode
- The component(s)/element(s) for which to defer rendering.When using HTML tables, you can change the default rootElement from "div" to "tbody". For example:
1import React from 'react' 2import RenderIfVisible from 'react-render-if-visible' 3import MyListItem from './list-item' 4 5const ESTIMATED_ITEM_HEIGHT = 200 6 7export const MyItemList = (items) => ( 8 <table className="my-list"> 9 <colgroup> 10 <col><col> 11 </colgroup> 12 {items.map(item => ( 13 <RenderIfVisible defaultHeight={ESTIMATED_ITEM_HEIGHT} rootElement={"tbody"} placeholderElement={"tr"}> 14 <MyListItem item={item} /> 15 </RenderIfVisible> 16 ))} 17 </table> 18)
The example above, builds a valid HTML table like the one shown below:
<table class="my-list">
<colgroup>
<col><col>
</colgroup>
<tbody class="renderIfVisible">
<tr><td>col1</td><td>col2</td></tr>
</tbody>
<tbody class="renderIfVisible">
<tr><td>col1</td><td>col2</td></tr>
</tbody>
<tbody class="renderIfVisible">
<tr><td>col1</td><td>col2</td></tr>
</tbody>
<tbody class="renderIfVisible">
<tr><td>col1</td><td>col2</td></tr>
</tbody>
... (offscreen)
<tbody class="renderIfVisible">
<tr class="renderIfVisible-placeholder" style="height:200px"></tr>
</tbody>
<tbody class="renderIfVisible">
<tr class="renderIfVisible-placeholder" style="height:200px"></tr>
</tbody>
<tbody class="renderIfVisible">
<tr class="renderIfVisible-placeholder" style="height:200px"></tr>
</tbody>
</table>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
7 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/22 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More