Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/rendering-hoist-jsx.md
1---2title: Hoist Static JSX Elements3impact: LOW4impactDescription: avoids re-creation5tags: rendering, jsx, static, optimization6---78## Hoist Static JSX Elements910Extract static JSX outside components to avoid re-creation.1112**Incorrect (recreates element every render):**1314```tsx15function LoadingSkeleton() {16return <div className="animate-pulse h-20 bg-gray-200" />17}1819function Container() {20return (21<div>22{loading && <LoadingSkeleton />}23</div>24)25}26```2728**Correct (reuses same element):**2930```tsx31const loadingSkeleton = (32<div className="animate-pulse h-20 bg-gray-200" />33)3435function Container() {36return (37<div>38{loading && loadingSkeleton}39</div>40)41}42```4344This is especially helpful for large and static SVG nodes, which can be expensive to recreate on every render.4546**Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, the compiler automatically hoists static JSX elements and optimizes component re-renders, making manual hoisting unnecessary.47