MSNCodeSNIPPETS← msncode.dev
snippets/react

Lazy Load a Component

Dynamically import a component to reduce bundle size

reactjavascriptlazyimport
JAVASCRIPT
const Heavy = lazy(() => import('./Heavy'));
// wrap in <Suspense fallback={<Spinner/>}>

More react snippets

Conditional Rendering (Short Circuit)

Render a component only if a condition is true

Forward Ref to Child Component

Pass a ref from parent to child component

useCallback to Memoize Function

Prevent unnecessary re-renders by memoizing callbacks

useEffect Cleanup Function

Clean up subscriptions and timers on unmount