Defining a schema for your props
As an alternative to using TypeScript types to define the shape of the props your component accepts, you may use Zod to define a schema for your props. You may do so if you want to edit the props visually in the Remotion Studio.
Prerequisites
If you want to use this feature, install zod and @remotion/zod-types for Remotion-specific types:
- npm
- yarn
- pnpm
bashnpm i zod @remotion/zod-types
bashnpm i zod @remotion/zod-types
bashyarn add zod @remotion/zod-types
bashyarn add zod @remotion/zod-types
bashpnpm i zod @remotion/zod-types
bashpnpm i zod @remotion/zod-types
Defining a schema
To define a schema for your props, use z.object():
tsximport {z } from "zod";export constmyCompSchema =z .object ({propOne :z .string (),propTwo :z .string (),});
tsximport {z } from "zod";export constmyCompSchema =z .object ({propOne :z .string (),propTwo :z .string (),});
Using z.infer(), you can turn the schema into a type:
tsxexport constMyComp :React .FC <z .infer <typeofmyCompSchema >> = ({propOne ,propTwo ,}) => {return (<div >props: {propOne }, {propTwo }</div >);};
tsxexport constMyComp :React .FC <z .infer <typeofmyCompSchema >> = ({propOne ,propTwo ,}) => {return (<div >props: {propOne }, {propTwo }</div >);};
Adding a schema to your composition
Use the schema prop to attach the schema to your <Composition>. Remotion will require you to specify matching defaultProps.
src/Root.tsxtsximportReact from "react";import {Composition } from "remotion";import {MyComponent ,myCompSchema } from "./MyComponent";export constRemotionRoot :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",}}/>);};
src/Root.tsxtsximportReact from "react";import {Composition } from "remotion";import {MyComponent ,myCompSchema } from "./MyComponent";export constRemotionRoot :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",}}/>);};
Editing props visually
When you have defined a schema for your props, you can edit them visually in the Remotion Studio. This is useful if you want to quickly try out different values for your props.
Supported types
All schemas that are supported by Zod are supported by Remotion.
Remotion requires that the top-level type is a z.object(), because the collection of props of a React component is always an object.
In addition to the built in types, the @remotion/zod-types package also provides zColor(), including a color picker interface for the Remotion Studio.