Skip to main content

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.ts
tsx
import { registerRoot } from "remotion";
import { RemotionVideo } from "./Video";
 
registerRoot(RemotionVideo);
src/index.ts
tsx
import { registerRoot } from "remotion";
import { RemotionVideo } from "./Video";
 
registerRoot(RemotionVideo);
src/Video.tsx
tsx
import MyComponent from "./MyComponent";
import MyOtherComponent from "./MyOtherComponent";
 
export const RemotionVideo = () => {
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.tsx
tsx
import MyComponent from "./MyComponent";
import MyOtherComponent from "./MyOtherComponent";
 
export const RemotionVideo = () => {
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";
 
const wait = delayRender();
 
loadWebAssembly().then(() => {
registerRoot(RemotionVideo);
continueRender(wait);
});
tsx
import { delayRender, continueRender, registerRoot } from "remotion";
import { RemotionVideo } from "./Video";
 
const wait = delayRender();
 
loadWebAssembly().then(() => {
registerRoot(RemotionVideo);
continueRender(wait);
});

See also