Skip to content

🎥 Make videos programmatically with React

reorganize docs

Jonny Burgera94c1803aaac
diff --git a/packages/docs/docs/parametrized-rendering.md b/packages/docs/docs/parametrized-rendering.md
index 7d284112b9..3250e73c85 100644
--- a/packages/docs/docs/parametrized-rendering.md
+++ b/packages/docs/docs/parametrized-rendering.md
@@ -1,15 +1,17 @@
---
image: /generated/articles-docs-parametrized-rendering.png
id: parametrized-rendering
-title: Parametrized rendering
+title: Parametrized videos
crumb: "How To"
---
```twoslash include example
-export const MyComponent: React.FC<{
+type Props = {
propOne: string;
propTwo: number;
-}> = ({propOne, propTwo}) => {
+}
+
+export const MyComponent: React.FC<Props> = ({propOne, propTwo}) => {
return (
<div>props: {propOne}, {propTwo}</div>
);
@@ -17,27 +19,32 @@ export const MyComponent: React.FC<{
// - MyComponent
```
-Parametrized rendering is the idea of creating a video template once and then render as many videos as you want with different parameters. Just like in regular React, we use props to reuse and customize components!
+You can parametrize the content of the videos using [React properties ("props")](https://react.dev/learn/passing-props-to-a-component).
## Defining accepted props
To define which props your video accepts, simply give your component the `React.FC` type and pass in a generic argument describing the shape of the props you want to accept.
-```tsx twoslash {1-2}
+```tsx twoslash title="src/MyComponent.tsx"
// @include: example-MyComponent
```
## Define default props
-When registering the component as a sequence, you can define the default props:
+When registering the component as a composition, you can define default props:
+
+```tsx twoslash {14-17} title="src/Root.tsx"
+// organize-imports-ignore
-```tsx twoslash {14-17}
// @filename: MyComponent.tsx
import React from "react";
-export const MyComponent: React.FC<{ propOne: string; propTwo: number }> = () =>
- null;
+export const MyComponent: React.FC<{
+ propOne: string;
+ propTwo: number;
+}> = () => null;
// @filename: Root.tsx
+
// ---cut---
import React from "react";
import { Composition } from "remotion";
@@ -63,7 +70,84 @@ export const Root: React.FC = () => {
};
```
-By using `React.FC`, you can ensure type safety and avoid errors caused by typos.
+Default props are useful so you don't preview your video with no data. Default props will overriden by input props.
+
+## Define a schema <AvailableFrom v="4.0.0"/>
+
+You can use [`z`](/docs/z) to define a typesafe schema for your composition.
+
+```tsx twoslash title="MyComp.tsx"
+import { z } from "remotion";
+
+export const myCompSchema = z.object({
+ propOne: z.string(),
+ propTwo: z.string(),
+});
+
+export const MyComp: React.FC<z.infer<typeof myCompSchema>> = ({
+ propOne,
+ propTwo,
+}) => {
+ return (
+ <div>
+ props: {propOne}, {propTwo}
+ </div>
+ );
+};
+```
+
+To define a schema, create a type using Zod and infer the props in your component using `z.infer`.
+Then, export the schema, and import it in your root file:
+
+```tsx twoslash title="src/Root.tsx" {14-18}
+// @filename: MyComponent.tsx
+import React from "react";
+import { z } from "remotion";
+
+export const myCompSchema = z.object({
+ propOne: z.string(),
+ propTwo: z.string(),
+});
+
+export const MyComponent: React.FC<z.infer<typeof myCompSchema>> = ({
+ propOne,
+ propTwo,
+}) => {
+ return (
+ <div>
+ <h1>{propOne}</h1>
+ <h2>{propTwo}</h2>
+ </div>
+ );
+};
+
+// @filename: Root.tsx
+// organize-imports-ignore
+// ---cut---
+import React from "react";
+import { Composition } from "remotion";
+import { MyComponent, myCompSchema } from "./MyComponent";
+
+export const RemotionRoot: React.FC = () => {
+ return (
+ <Composition
+ id="my-video"
+ component={MyComponent}
+ durationInFrames={100}
+ fps={30}
+ width={1920}
+ height={1080}
+ schema={myCompSchema}
+ defaultProps={{
+ propOne: "Hello World",
+ propTwo: "Welcome to Remotion",
+ }}
+ />
+ );
+};
+```
+
+If you define a schema, you will be able to visually manipulate the props in the Remotion Preview and render a parametrized video by filling out a form.
## Input props
@@ -146,7 +230,7 @@ _Available since v2.0._: You can also use the `getInputProps()` function to retr
## You can still use components as normal
Even if you have registered a component as a composition,
-you can still use it normally in your videos and pass its props directly. Default props don't apply in this case.
+you can still use it normally in your React markup and pass its props directly. Default props don't apply in this case.
```tsx twoslash
// @include: example-MyComponent
diff --git a/packages/docs/docs/the-fundamentals.md b/packages/docs/docs/the-fundamentals.md
index 518477be02..55c8bcc4ea 100644
--- a/packages/docs/docs/the-fundamentals.md
+++ b/packages/docs/docs/the-fundamentals.md
@@ -29,7 +29,7 @@ export const MyComposition = () => {
// - MyComposition
```
-The fundamental idea of Remotion is to give you a frame number and a blank canvas, to which you can render anything you want using [React](https://reactjs.org). This is an example React component that renders the current frame as text:
+The fundamental idea of Remotion is to give you a frame number and a blank canvas, to which you can render anything you want using [React](https://react.dev). This is an example React component that renders the current frame as text:
```tsx twoslash title="MyComposition.tsx"
// @include: example-MyComposition
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 4f1709a058..9c30b484bb 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -349,17 +349,16 @@ module.exports = {
items: [
"transforms",
"assets",
+ "data-fetching",
+ "parametrized-rendering",
+ "use-img-and-iframe",
"using-audio",
"fonts",
"using-randomness",
"audio-visualization",
"noise-visualization",
- "use-img-and-iframe",
- "javascript",
- "data-fetching",
"encoding",
"transparent-videos",
- "parametrized-rendering",
"dynamic-metadata",
"ssr",
"webpack",
@@ -372,6 +371,7 @@ module.exports = {
"render-as-gif",
"overlay",
"docker",
+ "javascript",
],
},
{