[React] Import on Visibility
2023-09-14 08:59:12 时间
Source: https://javascriptpatterns.vercel.app/patterns/performance-patterns/import-on-visibility
One way to dynamically import components on interaction, is by using the Intersection Observer API. There's a React hook called react-intersection-observer
that we can use to easily detect whether a component is visible in the viewport.
import { Suspense, lazy } from "react";
import { useInView } from "react-intersection-observer";
const Listing = lazy(() => import("./components/Listing"));
function ListingCard(props) {
const { ref, inView } = useInView();
return (
<div ref={ref}>
<Suspense fallback={<div />}>{inView && <Listing />}</Suspense>
</div>
);
}
相关文章
- React saga_react获取子组件ref
- TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab
- React Error: Failed at the xxx@0.1.0 start script 'react-scripts start'.
- 从react源码角度看React-Hydrate原理
- react源码分析:深度理解React.Context_2023-02-07
- 选中和取消选中事件on
- react 基础之组件篇二——Style in React
- ORA-28602: statement not permitted on tables containing bitmap indexes ORACLE 报错 故障修复 远程处理
- ORA-47305: Rule Set violation on string (string) ORACLE 报错 故障修复 远程处理
- ORA-02189: ON required ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-011640; Symbol: ER_GRP_RPL_TIMEOUT_ON_VIEW_AFTER_JOINING_GRP; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-08340: This command not allowed on nCUBE, only one thread is ever used. ORACLE 报错 故障修复 远程处理
- Making Bin Files on Linux System(linux制作bin文件)
- MySQL连接查询:活学活用ON条件(mysql连接查询on)
- delete cascadeMySQL:探索ON DELETE CASCADE功能(mysql支持on)
- Redis On the Rise: Understanding the Benefits of This InMemory Database Solution(redison)
- Oracle内连接ON极大提高数据查询性能(oracle内连接on)
- MySQL中ON的作用详解(mysql中on的作用)
- 深入MySQL解密On语句的使用方法(mysql中on使用方法)
- MySQL 中的 ON 含义及应用场景解析(mysql中on什么意思)
- 使用Oracle On关键字实现数据库连接(oracle on关键字)
- jQuery事件绑定.on()简要概述及应用