delayRender() and continueRender()
By calling delayRender
, you are signaling that a frame should not be immediately rendered and instead should wait on an asynchronous task to complete.
This method is useful if you for example want to call an API to fetch data before you render.
delayRender
returns an identifier. Once you have fetched data or finished the asynchronous task, you should call continueRender(identifier)
to let Remotion know that you are now ready to render.
Useful to know
You need to call
continueRender()
within 30 seconds of page load. This is the default timeout of puppeteer and it will throw if you miss to callcontinueRender()
.For every frame that is rendered, the whole page is reloaded, so the whole lifecycle of
delayRender
andcontinueRender
happens on every frame. If you are doing an API request, you can speed up the render and avoid rate limits by caching the request, for example by storing the data inlocalStorage
.You can call
delayRender
multiple times. The render will be blocked for as long as at least one blocking handle exists and that has not been cleared bycontinueRender()
.You should put
delayRender()
calls inside your components rather than placing them as a top-level statement, to avoid blocking a render if a different composition is rendered. Also, in the example below the call is wrapped in auseState()
to avoid creating multiple blocking calls when the component rerenders.
Example
tsx
import {useEffect ,useState } from "react";import {continueRender ,delayRender } from "remotion";Âexport constMyVideo = () => {const [data ,setData ] =useState (null);const [handle ] =useState (() =>delayRender ());ÂconstfetchData = async () => {constresponse = awaitfetch ("http://example.com/api");constjson = awaitresponse .json ();setData (json );ÂcontinueRender (handle );};ÂuseEffect (() => {fetchData ();}, []);return (<div >{data ? (<div >This video has data from an API! {JSON .stringify (data )}</div >) : null}</div >);};
tsx
import {useEffect ,useState } from "react";import {continueRender ,delayRender } from "remotion";Âexport constMyVideo = () => {const [data ,setData ] =useState (null);const [handle ] =useState (() =>delayRender ());ÂconstfetchData = async () => {constresponse = awaitfetch ("http://example.com/api");constjson = awaitresponse .json ();setData (json );ÂcontinueRender (handle );};ÂuseEffect (() => {fetchData ();}, []);return (<div >{data ? (<div >This video has data from an API! {JSON .stringify (data )}</div >) : null}</div >);};