Skip to content

🎥 Make videos programmatically with React

formatting

Jonny Burger0c735c3931a2
diff --git a/packages/docs/docs/integration-frameworks/angular.mdx b/packages/docs/docs/integration-frameworks/angular.mdx
index bd43bd31c1..b54d188088 100644
--- a/packages/docs/docs/integration-frameworks/angular.mdx
+++ b/packages/docs/docs/integration-frameworks/angular.mdx
@@ -12,7 +12,6 @@ import TabItem from '@theme/TabItem';
This guide explains how to integrate **Remotion** into an **Angular** project.
-
## Install required packages
Install Remotion and necessary dependencies:
@@ -90,14 +89,14 @@ To enable JSX support in Angular, update the `tsconfig.json` file by setting `"j
{
"compilerOptions": {
"jsx": "react",
- "skipLibCheck": true, // Recommended to avoid errors with certain libraries
+ "skipLibCheck": true // Recommended to avoid errors with certain libraries
// other options
}
}
```
:::note
-The "skipLibCheck": true setting is also recommended to prevent compatibility issues with certain library types.
+The `"skipLibCheck": true` setting is also recommended to prevent compatibility issues with certain library types.
:::
## Create a React wrapper component for Angular
@@ -108,63 +107,81 @@ To embed Remotion components in Angular, create a **wrapper component**:
2. Ensure each `.tsx` file imports React explicitly at the top of the file:
```tsx title="PlayerViewWrapper.tsx"
-import {AfterViewInit, Component, effect, ElementRef, EventEmitter, Input, OnDestroy, Output, signal, Signal, ViewChild, WritableSignal} from '@angular/core';
+import {
+ AfterViewInit,
+ Component,
+ effect,
+ ElementRef,
+ EventEmitter,
+ Input,
+ OnDestroy,
+ Output,
+ signal,
+ Signal,
+ ViewChild,
+ WritableSignal,
+} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterOutlet} from '@angular/router';
import React from 'react';
-import {createRoot, Root} from "react-dom/client";
-import {PlayerRef} from "@remotion/player";
-import {myCompSchema, PlayerView} from "./PlayerView";
-import {z} from "zod";
+import {createRoot, Root} from 'react-dom/client';
+import {PlayerRef} from '@remotion/player';
+import {myCompSchema, PlayerView} from './PlayerView';
+import {z} from 'zod';
-const rootDomID: string = "reactCounterWrapperId";
+const rootDomID: string = 'reactCounterWrapperId';
@Component({
selector: 'app-player-view',
standalone: true,
imports: [CommonModule, RouterOutlet],
- template: `
- <div id="${rootDomID}" #${rootDomID}></div>`,
+ template: ` <div id="${rootDomID}" #${rootDomID}></div>`,
})
export class PlayerViewWrapper implements AfterViewInit, OnDestroy {
@ViewChild(rootDomID, {static: false}) containerRef: ElementRef | undefined;
@Input({required: true}) data: Signal<z.infer<typeof myCompSchema>> = signal({
- titleText: "Welcome to Remotion",
- titleColor: "#000000",
- logoColor1: "#91EAE4",
- logoColor2: "#86A8E7",
- })
- @Output() onPaused = new EventEmitter<void>
+ titleText: 'Welcome to Remotion',
+ titleColor: '#000000',
+ logoColor1: '#91EAE4',
+ logoColor2: '#86A8E7',
+ });
+ @Output() onPaused = new EventEmitter<void>();
playerRef: WritableSignal<PlayerRef | undefined> = signal(undefined);
- private root?: Root
+ private root?: Root;
constructor() {
effect(() => {
- this.render()
- })
+ this.render();
+ });
}
ngAfterViewInit() {
- this.root = createRoot(this.getRootDomNode())
+ this.root = createRoot(this.getRootDomNode());
this.render();
- this.playerRef()?.play()
+ this.playerRef()?.play();
}
ngOnDestroy(): void {
- this.root?.unmount()
+ this.root?.unmount();
}
private getRootDomNode() {
if (!this.containerRef || !this.containerRef.nativeElement) {
- throw new Error("Cannot get root element. This should not happen.");
+ throw new Error('Cannot get root element. This should not happen.');
}
return this.containerRef.nativeElement;
}
protected render() {
if (!this.containerRef || !this.containerRef.nativeElement) return;
- this.root?.render(<PlayerView playerRefInstance={this.playerRef} data={this.data()} onPaused={() => this.onPaused.emit()} />)
+ this.root?.render(
+ <PlayerView
+ playerRefInstance={this.playerRef}
+ data={this.data()}
+ onPaused={() => this.onPaused.emit()}
+ />,
+ );
}
}
```
@@ -181,38 +198,43 @@ You can also pass an EventEmitter instead of a Signal.
This will get the reference to the player with `useRef`.
```tsx title="PlayerView.tsx"
-import React, {useEffect} from "react";
-import {Player, PlayerRef} from "@remotion/player";
-import {z} from "zod";
-import {HelloWorld} from "./HelloWorld";
-import {zColor} from "@remotion/zod-types";
-import {WritableSignal} from "@angular/core";
-
-export const PlayerView: React.FC<{ data: z.infer<typeof myCompSchema>, playerRefInstance: WritableSignal<PlayerRef | undefined>, onPaused?: () => void }> = ({data, playerRefInstance, onPaused}) => {
-
- const playerRef: React.RefObject<PlayerRef> = React.createRef()
+import React, {useEffect} from 'react';
+import {Player, PlayerRef} from '@remotion/player';
+import {z} from 'zod';
+import {HelloWorld} from './HelloWorld';
+import {zColor} from '@remotion/zod-types';
+import {WritableSignal} from '@angular/core';
+
+export const PlayerView: React.FC<{
+ data: z.infer<typeof myCompSchema>;
+ playerRefInstance: WritableSignal<PlayerRef | undefined>;
+ onPaused?: () => void;
+}> = ({data, playerRefInstance, onPaused}) => {
+ const playerRef: React.RefObject<PlayerRef> = React.createRef();
useEffect(() => {
if (playerRef.current) {
- playerRefInstance.set(playerRef.current)
+ playerRefInstance.set(playerRef.current);
// add callback when player pauses
playerRef.current.addEventListener('pause', () => {
- onPaused?.()
- })
+ onPaused?.();
+ });
}
- }, [])
- return <Player
- ref={playerRef}
- component={HelloWorld}
- durationInFrames={150}
- fps={30}
- compositionHeight={1080}
- compositionWidth={1920}
- inputProps={data}
- controls
- />
-}
+ }, []);
+ return (
+ <Player
+ ref={playerRef}
+ component={HelloWorld}
+ durationInFrames={150}
+ fps={30}
+ compositionHeight={1080}
+ compositionWidth={1920}
+ inputProps={data}
+ controls
+ />
+ );
+};
```
## Use the component in Angular
@@ -234,7 +256,7 @@ If your project uses **TailwindCSS**, ensure that it applies styles to `.tsx` fi
```js title="tailwind.config.js"
module.exports = {
content: [
- './src/**/*.{html,ts,tsx}', // Add .tsx files to Tailwind content paths
+ './src/**/*.{html,ts,tsx}', // Add .tsx files to Tailwind content paths
// other paths
],
// other Tailwind configurations
diff --git a/packages/docs/docs/integration-frameworks/vue-js.mdx b/packages/docs/docs/integration-frameworks/vue-js.mdx
index 8b1ab61fa6..afe370062d 100644
--- a/packages/docs/docs/integration-frameworks/vue-js.mdx
+++ b/packages/docs/docs/integration-frameworks/vue-js.mdx
@@ -12,7 +12,6 @@ import TabItem from '@theme/TabItem';
This guide explains how to integrate **Remotion** into a **VueJS** project.
-
## Install required packages
Install Remotion and necessary dependencies:
@@ -90,11 +89,12 @@ To enable JSX support in VueJS, update the `tsconfig.app.json` file by setting `
{
"compilerOptions": {
"jsx": "react",
- "jsxImportSource": "", // Recommended to avoid errors while building
+ "jsxImportSource": "" // Recommended to avoid errors while building
// other options
}
}
```
+
:::note
The "jsxImportSource": "" setting is also recommended to prevent build issues.
:::
@@ -104,10 +104,10 @@ The "jsxImportSource": "" setting is also recommended to prevent build issues.
To enable React support in Vite, update the `vite.config.ts` file by setting adding react to the plugins.
```ts title="vite.config.ts"
-import { fileURLToPath, URL } from 'node:url'
-import { defineConfig } from 'vite'
-import vue from '@vitejs/plugin-vue'
-import react from '@vitejs/plugin-react'
+import {fileURLToPath, URL} from 'node:url';
+import {defineConfig} from 'vite';
+import vue from '@vitejs/plugin-vue';
+import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [
@@ -118,10 +118,10 @@ export default defineConfig({
],
resolve: {
alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url))
+ '@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
-})
+});
```
## Create a React wrapper component for VueJS
@@ -191,44 +191,53 @@ This wrapper component will serve as the bridge between VueJs and Remotion’s R
This will get the reference to the player with `useRef`.
```tsx title="PlayerView.tsx"
-import React, {useEffect} from "react";
-import {Player, type PlayerRef} from "@remotion/player";
-import {HelloWorld} from "@/remotion/HelloWorld";
-import type {Ref} from "vue";
+import React, {useEffect} from 'react';
+import {Player, type PlayerRef} from '@remotion/player';
+import {HelloWorld} from '@/remotion/HelloWorld';
+import type {Ref} from 'vue';
export interface PlayerSchema {
- titleText: string
- titleColor: string
- logoColor1: string
- logoColor2: string
+ titleText: string;
+ titleColor: string;
+ logoColor1: string;
+ logoColor2: string;
}
-export const PlayerView = ({data, playerRefInstance, onPaused}: { data: PlayerSchema, playerRefInstance: Ref<PlayerRef>, onPaused?: () => void }): React.ReactElement => {
-
- const playerRef: React.RefObject<PlayerRef> = React.createRef()
-
- useEffect(() => {
- if (playerRef.current) {
- playerRefInstance.value = playerRef.current
-
- // add callback when player pauses
- playerRef.current.addEventListener('pause', () => {
- onPaused?.()
- })
- }
- }, [])
-
- return <Player
- ref={playerRef}
- component={HelloWorld}
- durationInFrames={150}
- fps={30}
- compositionHeight={1080}
- compositionWidth={1920}
- inputProps={data}
- controls
+export const PlayerView = ({
+ data,
+ playerRefInstance,
+ onPaused,
+}: {
+ data: PlayerSchema;
+ playerRefInstance: Ref<PlayerRef>;
+ onPaused?: () => void;
+}): React.ReactElement => {
+ const playerRef: React.RefObject<PlayerRef> = React.createRef();
+
+ useEffect(() => {
+ if (playerRef.current) {
+ playerRefInstance.value = playerRef.current;
+
+ // add callback when player pauses
+ playerRef.current.addEventListener('pause', () => {
+ onPaused?.();
+ });
+ }
+ }, []);
+
+ return (
+ <Player
+ ref={playerRef}
+ component={HelloWorld}
+ durationInFrames={150}
+ fps={30}
+ compositionHeight={1080}
+ compositionWidth={1920}
+ inputProps={data}
+ controls
/>
-}
+ );
+};
```
## Use the component in VueJS
@@ -236,7 +245,7 @@ export const PlayerView = ({data, playerRefInstance, onPaused}: { data: PlayerSc
To display the Remotion player within an VueJS template, add your new wrapper component wherever you'd like the player to appear:
```html
-<PlayerWrapper @paused=onPaused :data="data" />
+<PlayerWrapper @paused="onPaused" :data="data" />
```
This VueJS component tag will render the Remotion player, allowing you to pass data or configuration as needed through VueJS's data binding.
@@ -250,9 +259,10 @@ If your project uses **TailwindCSS**, ensure that it applies styles to `.tsx` fi
```js title="tailwind.config.js"
module.exports = {
content: [
- "./index.html",
- "./src/**/*.{vue,tsx}",, // Add .tsx files to Tailwind content paths
+ './index.html',
+ './src/**/*.{vue,tsx}', // Add .tsx files to Tailwind content paths
// other paths
+ ,
],
// other Tailwind configurations
};