registerRoot()
registerRoot
is a function that registers the root component of the Remotion project. In the root component, one or multiple compositions should be returned (in the case of multiple compositions, they should be wrapped in a React Fragment).
info
registerRoot()
should live in a file that is separate from the list of compositions. This is because when using React Fast Refresh, all the code in the file that gets refreshed gets executed again, however, this function should only be called once.
Example
src/index.tstsx
import {registerRoot } from "remotion";import {RemotionVideo } from "./Video";registerRoot (RemotionVideo );
src/index.tstsx
import {registerRoot } from "remotion";import {RemotionVideo } from "./Video";registerRoot (RemotionVideo );
src/Video.tsxtsx
importMyComponent from "./MyComponent";importMyOtherComponent from "./MyOtherComponent";export constRemotionVideo = () => {return (<><Composition id ="comp"fps ={30}height ={1080}width ={1920}component ={MyComponent }/><Composition id ="anothercomp"fps ={30}height ={1080}width ={1920}component ={MyOtherComponent }/></>);};
src/Video.tsxtsx
importMyComponent from "./MyComponent";importMyOtherComponent from "./MyOtherComponent";export constRemotionVideo = () => {return (<><Composition id ="comp"fps ={30}height ={1080}width ={1920}component ={MyComponent }/><Composition id ="anothercomp"fps ={30}height ={1080}width ={1920}component ={MyOtherComponent }/></>);};
Defer registerRoot()
In some cases, such as dynamically importing roots or loading WebAssembly, you might want to defer the loading of registerRoot(). If you are doing that, you need to tell Remotion to wait by using the delayRender()
/ continueRender()
pattern.
tsx
import {delayRender ,continueRender ,registerRoot } from "remotion";import {RemotionVideo } from "./Video";constwait =delayRender ();loadWebAssembly ().then (() => {registerRoot (RemotionVideo );continueRender (wait );});
tsx
import {delayRender ,continueRender ,registerRoot } from "remotion";import {RemotionVideo } from "./Video";constwait =delayRender ();loadWebAssembly ().then (() => {registerRoot (RemotionVideo );continueRender (wait );});