Skip to content

🎥 Make videos programmatically with React

Docs: Clarify purpose of getInputProps()

Jonny Burgerc19a0d8f9f59
diff --git a/packages/docs/docs/calculate-metadata.mdx b/packages/docs/docs/calculate-metadata.mdx
index 51b7564c51..343586094b 100644
--- a/packages/docs/docs/calculate-metadata.mdx
+++ b/packages/docs/docs/calculate-metadata.mdx
@@ -11,13 +11,19 @@ crumb: 'API'
Use it if you:
-<Step>1</Step> need to make the `durationInFrames`, `width`, `height`, or `fps` <a href="/docs/dynamic-metadata">dynamic based on some data</a>
-<br />
+<div>
+ <Step>1</Step> need to make the `durationInFrames`, `width`, `height`, or `fps` <a href="/docs/dynamic-metadata">dynamic based on some data</a>
+</div>
+<div>
+
<Step>2</Step> want to transform the props passed to the composition, for example to do <a href="/docs/data-fetching">data fetching</a>
-<br />
+</div>
+<div>
<Step>3</Step> want to add a per-composition default codec
-<br />
+</div>
+<div>
<Step>4</Step> want to run code once, before the actual render starts.
+</div>
The `calculateMetadata()` function is called a single time, independently from the concurrency of the render.
It runs in a separate tab, as part of the render process calling [`selectComposition()`](/docs/renderer/select-composition).
diff --git a/packages/docs/docs/get-input-props.mdx b/packages/docs/docs/get-input-props.mdx
index 7ce028ccbd..72c52df711 100644
--- a/packages/docs/docs/get-input-props.mdx
+++ b/packages/docs/docs/get-input-props.mdx
@@ -2,19 +2,28 @@
image: /generated/articles-docs-get-input-props.png
title: getInputProps()
id: get-input-props
-crumb: "API"
+crumb: 'API'
---
_Available from v2.0_.
-Using this method, you can retrieve inputs that you pass in from the command line using [`--props`](/docs/cli), or the [`inputProps`](/docs/ssr) parameter if you are using the Node.JS API.
+Using this method, you can retrieve inputs that you pass in from the command line using [`--props`](/docs/cli), or the [`inputProps`](/docs/ssr) parameter if you are using the Node.JS APIs ([`renderMedia()`](/docs/renderer/render-media), [`renderMediaOnLambda()`](/docs/lambda/render-media-on-lambda)).
-You should whenever possible prefer to retrieve props directly in your composition, like you would read props from a component if you were to code a React application, but this method is useful if you want to retrieve the input props outside of a composition.
+This method is useful if you want to retrieve the input props in the [root component](/docs/terminology/root-file).
:::info
This method is not available when inside a Remotion Player. Instead, get the props as React props from the component you passed as the `component` prop to the player.
:::
+## You might not need this API
+
+Prefer the following ways of getting your input props:
+
+- A component that was rendered as a [composition](/docs/composition) will retrieve the input props as regular props.
+- In the [root component](/docs/terminology/root-file), you can get the input props by using the [`calculateMetadata()`](/docs/calculate-metadata) function.
+
+In both cases, you can type the props, which is better than using this API which returns a non-typesafe object.
+
## API
Pass in a [parseable](/docs/cli) JSON representation using the `--props` flag to either `remotion studio` or `remotion render`:
@@ -35,12 +44,27 @@ You may also specify a file containing JSON and Remotion will parse the file for
npx remotion render --props=./path/to/props.json
```
-You can then access the props in JavaScript:
-
-```tsx twoslash
-const getInputProps = () => ({ hello: "world" } as const);
+You can then access the props anywhere in your Remotion project:
+
+```tsx twoslash {3}
+import {Composition} from 'remotion';
+const getInputProps = () => ({hello: 'world'}) as const;
+const MyComp: React.FC = () => null;
+const config = {
+ component: MyComp,
+ durationInFrames: 100,
+ fps: 30,
+ width: 1000,
+ height: 1000,
+ id: 'MyComp',
+} as const;
// ---cut---
-const { hello } = getInputProps(); // "world"
+
+export const Root: React.FC = () => {
+ const {hello} = getInputProps(); // "world"
+
+ return <Composition {...config} />;
+};
```
In this example, the props also get passed to the component of the composition with the id `my-composition`.