useDelayRender()v4.0.342
A React hook that provides scoped delayRender
and continueRender
functions for React components. This is the recommended approach instead of using the global delayRender()
and continueRender()
functions directly.
The hook returns an object with delayRender
and continueRender
functions that are scoped to the component's environment context.
Example
tsx
import {useCallback ,useEffect ,useState } from 'react';import {useDelayRender } from 'remotion';export constMyVideo = () => {const [data ,setData ] =useState (null);const {delayRender ,continueRender } =useDelayRender ();const [handle ] =useState (() =>delayRender ('Fetching API data'));constfetchData =useCallback (async () => {constresponse = awaitfetch ('http://example.com/api');constjson = awaitresponse .json ();setData (json );continueRender (handle );}, [handle ,continueRender ]);useEffect (() => {fetchData ();}, [fetchData ]);return <div >{data ? <div >This video has data from an API! {JSON .stringify (data )}</div > : null}</div >;};
Multiple delays
You can create multiple delay handles for different asynchronous operations:
tsx
import {useCallback ,useEffect ,useState } from 'react';import {useDelayRender } from 'remotion';export constMyVideo = () => {const {delayRender ,continueRender } =useDelayRender ();const [dataHandle ] =useState (() =>delayRender ('Fetching API data'));const [imageHandle ] =useState (() =>delayRender ('Loading image'));useEffect (() => {// Fetch API datafetch ('/api/data').then (() =>continueRender (dataHandle ));// Load imageconstimg = newImage ();img .onload = () =>continueRender (imageHandle );img .src = '/image.jpg';}, [dataHandle ,imageHandle ,continueRender ]);return <div >Content</div >;};
Configuration options
You can pass options to customize timeout and retry behavior:
tsx
import {useDelayRender } from 'remotion';export constMyVideo = () => {const {delayRender ,continueRender } =useDelayRender ();consthandle =delayRender ('Loading asset...', {timeoutInMilliseconds : 7000,retries : 1,});// ... rest of componentreturn <div />;};
API
tsx
function useDelayRender(): {delayRender: (label?: string, options?: DelayRenderOptions) => number;continueRender: (handle: number) => void;};
Return value
Returns an object with two functions:
-
delayRender(label?, options?)
: Creates a new delay handlelabel
(optional): A string label to help identify this delay in error messagesoptions
(optional): Configuration options:timeoutInMilliseconds
(optional): Custom timeout for this specific delayretries
(optional): Number of retries if the delay times out
- Returns: A numeric handle to identify this delay
-
continueRender(handle)
: Continues render for a specific handlehandle
: The numeric handle returned bydelayRender()
Why use useDelayRender()
over global delayRender()
?
This hook provides a more React-friendly API and is future-proof for browser rendering.
It is recommended to use this hook instead of the global delayRender()
function.
Timeout and error handling
The hook uses the same timeout and error handling behavior as delayRender()
.
See also
delayRender()
- The underlying APIcontinueRender()
- Manual render continuationcancelRender()
- Cancel render on error- Data fetching guide