Skip to content

πŸŽ₯ Make videos programmatically with React

Docs: Add interactivity best practices (#8785)

Jonny Burger3d971c91f26b
diff --git a/packages/docs/docs/studio/interactivity-best-practices.mdx b/packages/docs/docs/studio/interactivity-best-practices.mdx
new file mode 100644
index 0000000000..1f3fd03de9
--- /dev/null
+++ b/packages/docs/docs/studio/interactivity-best-practices.mdx
@@ -0,0 +1,153 @@
+---
+image: /generated/articles-docs-studio-interactivity-best-practices.png
+title: Interactivity best practices
+crumb: "Remotion Studio"
+---
+
+# Interactivity best practices
+
+Write editable Remotion components so the [Studio interactivity](/docs/studio/interactivity) can understand the values that should be changed visually.
+
+When a value is shown as computed in the Studio, it often means that the value is hidden behind a variable, helper function, conditional expression or transform string.
+
+## Use `Interactive.*` for tweakable elements
+
+Use the [`Interactive`](/docs/interactive) namespace when an HTML or SVG element should be selected, moved or edited in the Studio.
+
+```tsx title="Interactive elements"
+// πŸ‘ Selectable and editable in the Studio
+<Interactive.Div style={{fontSize: 80, padding: 24}}>Hello</Interactive.Div>
+
+// πŸ‘Ž A regular element is not Studio-editable
+<div style={{fontSize: 80, padding: 24}}>Hello</div>
+```
+
+For a custom component, see [Make a component interactive](/docs/studio/make-component-interactive).
+
+## Keep editable values visible
+
+Put values that should be edited in the Studio directly into the JSX.
+This applies to static style values, keyframes, easing and transform props.
+
+```tsx title="Inline values"
+// πŸ‘ Inline values can be standardized and keyframed
+<Interactive.Div
+ style={{
+ color: 'white',
+ fontSize: 80,
+ scale: interpolate(frame, [0, 30], [0, 1], {
+ easing: Easing.spring({damping: 200}),
+ }),
+ rotate: interpolate(frame, [0, 30], ['0deg', '20deg']),
+ translate: interpolate(frame, [0, 30], ['0px 0px', '0px 120px']),
+ }}
+/>
+
+// πŸ‘Ž Values hidden behind variables, helpers or strings become computed
+const container: React.CSSProperties = {
+ color: 'white',
+ fontSize: 80,
+};
+const translateY = interpolate(frame, [0, 30], [0, 120]);
+const rotation = interpolate(frame, [0, 30], [0, 20]);
+
+<Interactive.Div
+ style={{
+ ...container,
+ transform: `translateY(${translateY}px) rotate(${rotation}deg)`,
+ }}
+/>
+```
+
+Use standalone [`spring()`](/docs/spring) only when the animation needs a frame-driven physical spring simulation.
+Use individual CSS transform properties such as `scale`, `rotate` and `translate` instead of composing a `transform` string.
+
+## Keep composition metadata inline
+
+When scaffolding a composition, keep the component and its [`<Composition>`](/docs/composition) registration in the same file.
+Keep static `width`, `height`, `fps`, `durationInFrames` and [`defaultProps`](/docs/composition#defaultprops) inline.
+
+The Props editor can save visual edits back to your code when `defaultProps` is an inline object literal on `<Composition>` or [`<Still>`](/docs/still).
+If the Studio shows `` `defaultProps` prop must be a hardcoded value in the <Composition/> tag ``, move the values into the JSX.
+
+```tsx title="Composition metadata"
+// πŸ‘ Static metadata and defaults are inline and nearby
+<Composition
+ id="my-video"
+ component={MyComponent}
+ durationInFrames={150}
+ fps={30}
+ width={1920}
+ height={1080}
+ defaultProps={{title: 'Hello', color: '#0b84ff'}}
+/>
+
+// πŸ‘Ž Static metadata is hidden behind helpers or variables
+const defaultProps = {title: 'Hello', color: '#0b84ff'};
+const calculateMetadata = () => {
+ return {durationInFrames: 150, fps: 30, width: 1920, height: 1080};
+};
+
+<Composition
+ id="my-video"
+ component={MyComponent}
+ calculateMetadata={calculateMetadata}
+ defaultProps={{
+ title: 'Hello',
+ }}
+/>
+```
+
+Use [`calculateMetadata()`](/docs/calculate-metadata) when metadata depends on dynamic input props, fetched data or asset metadata.
+
+## Keep effects editable
+
+Keep editable effect parameters inline in the effect call and keep the effect array shape unconditional.
+
+```tsx title="Effects"
+// πŸ‘ Parameters are inline and the array shape is stable
+<CanvasImage
+ src={src}
+ width={1280}
+ height={720}
+ effects={[
+ radialProgressiveBlur({
+ center: [0.5, 0.5],
+ point1: [0.86, 0.36],
+ point2: [0.68, 0.84],
+ }),
+ ]}
+/>
+
+// πŸ‘Ž Values are hidden and the effect only exists conditionally
+const center = [0.5, 0.5] as const;
+<CanvasImage
+ src={src}
+ width={1280}
+ height={720}
+ effects={enabled ? [
+ radialProgressiveBlur({
+ center,
+ }),
+ ] : []}
+/>
+```
+
+Render separate elements if one version should have effects and another should not.
+
+## AI agent prompt
+
+If a component is not editable enough in the Studio, give your coding agent a targeted prompt:
+
+```txt
+/remotion-best-practices Make this component interactive for Remotion Studio. Use Interactive.* for tweakable elements, keep editable style values and effect params inline, keep defaultProps inline on the Composition, prefer interpolate() keyframes, and use scale/rotate/translate instead of transform strings.
+```
+
+## See also
+
+- [Studio interactivity](/docs/studio/interactivity)
+- [Make a component interactive](/docs/studio/make-component-interactive)
+- [Visual editing](/docs/visual-editing)
+- [`Interactive`](/docs/interactive)
+- [`interpolate()`](/docs/interpolate)
+- [`Easing.spring()`](/docs/easing#spring)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 4ab75ccaa6..8df4478319 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1307,6 +1307,7 @@ const sidebars: SidebarsConfig = {
'studio/shortcuts',
'studio/quick-switcher',
'studio/interactivity',
+ 'studio/interactivity-best-practices',
'studio/make-component-interactive',
'studio/deploy-static',
'studio/deploy-server',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index ad5abca44b..a48f70adfb 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -6672,6 +6672,15 @@ export const articles = [
noAi: false,
slug: 'studio/go-to-composition',
},
+ {
+ id: 'studio/interactivity-best-practices',
+ title: 'Interactivity best practices',
+ relativePath: 'docs/studio/interactivity-best-practices.mdx',
+ compId: 'articles-docs-studio-interactivity-best-practices',
+ crumb: 'Remotion Studio',
+ noAi: false,
+ slug: 'studio/interactivity-best-practices',
+ },
{
id: 'studio/interactivity',
title: 'Interactivity',
diff --git a/packages/docs/static/generated/articles-docs-studio-interactivity-best-practices.png b/packages/docs/static/generated/articles-docs-studio-interactivity-best-practices.png
new file mode 100644
index 0000000000..3406e57d86
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-interactivity-best-practices.png differ
diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.md
index 6827c18578..486bd46467 100644
--- a/packages/skills/skills/remotion/SKILL.md
+++ b/packages/skills/skills/remotion/SKILL.md
@@ -44,23 +44,21 @@ export const FadeIn = () => {
};
```
-Prefer:
-
```tsx
+// πŸ‘ Inline editable keyframes and transform shorthands
style={{
scale: interpolate(frame, [0, 100], [0, 1]),
translate: interpolate(frame, [0, 100], ["0px 0px", "100px 100px"]),
rotate: interpolate(frame, [0, 100], ["20deg", "90deg"]),
}}
-```
-
-Over:
-```tsx
+// πŸ‘Ž Hidden values and transform strings become harder to edit in Studio
const scale = interpolate(frame, [0, 100], [0, 1]);
+const translateY = interpolate(frame, [0, 100], [0, 120]);
+const rotation = interpolate(frame, [0, 100], [0, 20]);
style={{
- transform: `scale(${scale})`,
+ transform: `scale(${scale}) translateY(${translateY}px) rotate(${rotation}deg)`,
}}
```
@@ -176,15 +174,16 @@ export const RemotionRoot = () => {
};
```
-Metadata can also be calculated dynamically:
+For scaffolds that should stay editable in Studio, keep the component and `<Composition>` registration in the same file so the dimensions, duration, FPS, and defaults stay visible next to the rendered code.
+Use `defaultProps` for composition-wide values and keep it as an inline object literal on `<Composition>` or `<Still>`.
-```tsx
-import { Composition, CalculateMetadataFunction } from "remotion";
-import { MyComposition, MyCompositionProps } from "./MyComposition";
+Metadata can also be calculated dynamically when it depends on input props, fetched data, or asset metadata:
-const calculateMetadata: CalculateMetadataFunction<
- MyCompositionProps
-> = async ({ props, abortSignal }) => {
+```tsx
+const calculateMetadata: CalculateMetadataFunction<Props> = async ({
+ props,
+ abortSignal,
+}) => {
const data = await fetch(`https://api.example.com/video/${props.videoId}`, {
signal: abortSignal,
}).then((res) => res.json());
@@ -200,19 +199,15 @@ const calculateMetadata: CalculateMetadataFunction<
};
};
-export const RemotionRoot = () => {
- return (
- <Composition
- id="MyComposition"
- component={MyComposition}
- fps={30}
- width={1080}
- height={1080}
- defaultProps={{ videoId: "abc123" }}
- calculateMetadata={calculateMetadata}
- />
- );
-};
+<Composition
+ id="MyComposition"
+ component={MyComposition}
+ fps={30}
+ width={1080}
+ height={1080}
+ defaultProps={{ videoId: "abc123" }}
+ calculateMetadata={calculateMetadata}
+/>;
```
## Starting preview
diff --git a/packages/skills/skills/remotion/rules/calculate-metadata.md b/packages/skills/skills/remotion/rules/calculate-metadata.md
index 54df5ffb21..2fa4111906 100644
--- a/packages/skills/skills/remotion/rules/calculate-metadata.md
+++ b/packages/skills/skills/remotion/rules/calculate-metadata.md
@@ -8,6 +8,8 @@ metadata:
# Using calculateMetadata
Use `calculateMetadata` on a `<Composition>` to dynamically set duration, dimensions, and transform props before rendering.
+Use it when metadata depends on input props, fetched data, or asset metadata.
+For static dimensions, duration, FPS, and initial props, inline the values on `<Composition>` instead.
```tsx
<Composition
diff --git a/packages/skills/skills/remotion/rules/compositions.md b/packages/skills/skills/remotion/rules/compositions.md
index 4f6b865625..445ee777d6 100644
--- a/packages/skills/skills/remotion/rules/compositions.md
+++ b/packages/skills/skills/remotion/rules/compositions.md
@@ -7,36 +7,48 @@ metadata:
A `<Composition>` defines the component, width, height, fps and duration of a renderable video.
-## Default Props
+## Default Props and scaffold metadata
Pass `defaultProps` to provide initial values for your component.
Values must be JSON-serializable (`Date`, `Map`, `Set`, and `staticFile()` are supported).
+Use `defaultProps` for composition-wide values that should be visible and editable before the video renders.
-```tsx
-import { Composition } from "remotion";
-import { MyComposition, MyCompositionProps } from "./MyComposition";
+For Studio editing, keep `defaultProps` as an inline object literal on `<Composition>` or `<Still>`.
+Do not store it in a variable, import it, spread it, create it with a helper, or wrap it in `satisfies`.
+When scaffolding, keep the component and `<Composition>` registration in the same file so `width`, `height`, `fps`, `durationInFrames`, and `defaultProps` are visible next to the code that uses them.
+Use `type` declarations for props rather than `interface` to ensure `defaultProps` type safety.
-export const RemotionRoot = () => {
- return (
- <Composition
- id="MyComposition"
- component={MyComposition}
- durationInFrames={100}
- fps={30}
- width={1080}
- height={1080}
- defaultProps={
- {
- title: "Hello World",
- color: "#ff0000",
- } satisfies MyCompositionProps
- }
- />
- );
+```tsx
+type Props = {
+ readonly title: string;
};
-```
-Use `type` declarations for props rather than `interface` to ensure `defaultProps` type safety.
+export const MyComposition = ({ title }: Props) => <h1>{title}</h1>;
+
+const defaultProps = { title: "Hello World" };
+
+// πŸ‘ Inline metadata and defaults
+<Composition
+ id="MyComposition"
+ component={MyComposition}
+ durationInFrames={100}
+ fps={30}
+ width={1080}
+ height={1080}
+ defaultProps={{ title: "Hello World" }}
+/>;
+
+// πŸ‘Ž Hidden defaults cannot be saved back by Studio
+<Composition
+ id="OtherComposition"
+ component={MyComposition}
+ durationInFrames={100}
+ fps={30}
+ width={1080}
+ height={1080}
+ defaultProps={defaultProps}
+/>;
+```
## Folders
@@ -81,15 +93,14 @@ export const RemotionRoot = () => {
## Calculate Metadata
-Use `calculateMetadata` to make dimensions, duration, or props dynamic based on data.
+Use `calculateMetadata` to make dimensions, duration, or props dynamic based on input props, fetched data, or asset metadata.
+For static dimensions, duration, FPS, and initial props, inline the values on `<Composition>`.
```tsx
-import { Composition, CalculateMetadataFunction } from "remotion";
-import { MyComposition, MyCompositionProps } from "./MyComposition";
-
-const calculateMetadata: CalculateMetadataFunction<
- MyCompositionProps
-> = async ({ props, abortSignal }) => {
+const calculateMetadata: CalculateMetadataFunction<Props> = async ({
+ props,
+ abortSignal,
+}) => {
const data = await fetch(`https://api.example.com/video/${props.videoId}`, {
signal: abortSignal,
}).then((res) => res.json());
@@ -103,19 +114,15 @@ const calculateMetadata: CalculateMetadataFunction<
};
};
-export const RemotionRoot = () => {
- return (
- <Composition
- id="MyComposition"
- component={MyComposition}
- fps={30}
- width={1080}
- height={1080}
- defaultProps={{ videoId: "abc123" }}
- calculateMetadata={calculateMetadata}
- />
- );
-};
+<Composition
+ id="MyComposition"
+ component={MyComposition}
+ fps={30}
+ width={1080}
+ height={1080}
+ defaultProps={{ videoId: "abc123" }}
+ calculateMetadata={calculateMetadata}
+/>;
```
The function can return `props`, `durationInFrames`, `width`, `height`, `fps`, and codec-related defaults. It runs once before rendering begins.
diff --git a/packages/skills/skills/remotion/rules/timing.md b/packages/skills/skills/remotion/rules/timing.md
index 887e939a9d..ef27876f70 100644
--- a/packages/skills/skills/remotion/rules/timing.md
+++ b/packages/skills/skills/remotion/rules/timing.md
@@ -30,20 +30,19 @@ const opacity = interpolate(frame, [0, 100], [0, 1], {
When an animation should be editable in Remotion Studio, keep the `interpolate()` call directly in the `style` prop and prefer individual CSS transform properties:
```tsx
+// πŸ‘ Inline editable keyframes and transform shorthands
style={{
scale: interpolate(frame, [0, 100], [0, 1]),
translate: interpolate(frame, [0, 100], ["0px 0px", "100px 100px"]),
rotate: interpolate(frame, [0, 100], ["20deg", "90deg"]),
}}
-```
-
-Avoid extracting the value and composing a `transform` string:
-```tsx
-const scale = interpolate(frame, [0, 100], [0, 1]);
+// πŸ‘Ž Hidden values and transform strings become computed in Studio
+const translateY = interpolate(frame, [0, 100], [0, 120]);
+const rotation = interpolate(frame, [0, 100], [0, 20]);
style={{
- transform: `scale(${scale})`,
+ transform: `translateY(${translateY}px) rotate(${rotation}deg)`,
}}
```