DocsAPISyntaxReactPlaygroundBlogCommunity
  • Playground
  • Blog
  • Community
  • X
  • Bluesky
  • GitHub
  • Forum
rescript-react
Overview
  • Introduction
  • Installation
  • Migrate from JSX v3
Main Concepts
  • Elements & JSX
  • Rendering Elements
  • Components and Props
  • Arrays and Keys
  • Events
  • Refs and the DOM
  • Context
  • memo
  • Styling
  • Router
  • Lazy Components
  • Import / Export ReactJS
Hooks & State Management
  • Hooks & State Management Overview
  • useEffect Hook
  • useState Hook
  • useReducer Hook
  • useContext Hook
  • useRef Hook
  • Build A Custom Hook
Guides
  • Beyond JSX
  • Forwarding Refs
  • Extensions of props
Extra
  • LLMs
Docs / rescript-react / Lazy Components
Edit

Lazy Components

It's good practice to delay loading the JavaScript required to render components you're not actually showing yet. This helps with performance and makes your application load faster.

React ships with an API for dynamically loading components. In this little guide we'll show you how to dynamically load React components in ReScript.

Note: This section requires the latest @rescript/react bindings to be installed (0.12.0-alpha.2 and above).

ReScript comes with APIs for doing dynamic imports both for single values and for entire modules. These APIs make dynamically importing React components easy.

Let's look at a small example. First we'll define a simple component:

RES
// Title.res @react.component let make = (~text) => { <div className="title">{text->React.string}</div> }

Now we can dynamically import the <Title/> component by passing the result of our dynamic import to React.lazy_:

RESCRIPT
// SomeOtherFile.res module LazyTitle = { let make = React.lazy_(() => import(Title.make)) } let titleJsx = <LazyTitle text="Hello!" />

That's all the code we need! The new <LazyTitle /> component behaves exactly the same as the wrapped <Title /> component, but will be lazy loaded via React's built-in lazy mechanism.

You can read more about import and dynamic import in ReScript in this part of the documentation.

RouterImport / Export ReactJS

© 2025 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on