getInputProps()
使用此方法,你可以通过 --props 从命令行检索你传入的输入,或如果你使用 Node.JS API,则使用 inputProps 参数 (renderMedia(), renderMediaOnLambda())。
🌐 Using this method, you can retrieve inputs that you pass in from the command line using --props, or the inputProps parameter if you are using the Node.JS APIs (renderMedia(), renderMediaOnLambda()).
如果你想在 根组件 中获取输入属性,这种方法很有用。
🌐 This method is useful if you want to retrieve the input props in the root component.
在 <Player> 内或客户端渲染时,此方法不可用。相反,请从你传递给播放器的 component 属性的组件中,将其作为 React 属性获取 props。
🌐 This method is not available when inside a <Player> or when client-side rendering. Instead, get the props as React props from the component you passed as the component prop to the player.
你可能不需要这个API
🌐 You might not need this API
更倾向于以下方式获取你的输入属性:
🌐 Prefer the following ways of getting your input props:
- 作为组合渲染的组件将像获取普通 props 一样获取输入 props。
- 在根组件中,你可以使用
calculateMetadata()函数获取输入属性。
在这两种情况下,你都可以为 props 键入类型,这比使用返回非类型安全对象的这个 API 要好。
🌐 In both cases, you can type the props, which is better than using this API which returns a non-typesafe object.
应用编程接口
🌐 API
使用 --props 标志将可解析的 JSON 表示传递给 remotion studio 或 remotion render :
🌐 Pass in a parseable JSON representation using the --props flag to either remotion studio or remotion render:
npx remotion render --props='{"hello": "world"}'要模拟它的行为,你在使用 Remotion Studio 时也可以传递 props:
🌐 To simulate how it behaves, you can also pass props when using the Remotion Studio:
npx remotion studio --props='{"hello": "world"}'你还可以指定一个包含 JSON 的文件,Remotion 会为你解析该文件:
🌐 You may also specify a file containing JSON and Remotion will parse the file for you:
npx remotion render --props=./path/to/props.json然后你可以在你的 Remotion 项目的任何地方访问这些 props:
🌐 You can then access the props anywhere in your Remotion project:
export const Root : React .FC = () => {
const {hello } = getInputProps (); // "world"
return <Composition {...config } />;
};在这个例子中,props 也会被传递给 id 为 my-composition 的组合组件。
🌐 In this example, the props also get passed to the component of the composition with the id my-composition.
兼容性
🌐 Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||
No-op, returns {} | No-op, returns {} | No-op, returns {} | No-op, returns {} | No-op, returns {} | |||||
另请参阅
🌐 See also