Skip to main content

getInputProps()

从 v2.0 版本开始可用

使用此方法,您可以检索通过 --props 从命令行传递的输入,或者如果您正在使用 Node.JS API,则可以使用 inputProps 参数。

在您的组合中直接检索 props 是首选方法,就像您在编写 React 应用程序时从组件中读取 props 一样,但是如果您想在组合之外检索输入 props,则此方法很有用。

info

在 Remotion Player 中无法使用此方法。相反,从您作为 component prop 传递给播放器的组件中获取 props 作为 React props。

API

通过使用 --props 标志将可解析的 JSON 表示传递给 remotion studioremotion render

bash
npx remotion render --props='{"hello": "world"}'
bash
npx remotion render --props='{"hello": "world"}'

为了模拟其行为,您还可以在使用 Remotion Studio 时传递 props:

bash
npx remotion studio --props='{"hello": "world"}'
bash
npx remotion studio --props='{"hello": "world"}'

您还可以指定包含 JSON 的文件,Remotion 将为您解析该文件:

bash
npx remotion render --props=./path/to/props.json
bash
npx remotion render --props=./path/to/props.json

然后可以在 JavaScript 中访问 props:

tsx
const { hello } = getInputProps(); // "world"
tsx
const { hello } = getInputProps(); // "world"

在此示例中,props 也会传递给具有 id my-composition 的组合件的组件。

另请参阅