Skip to main content

updateDefaultProps()v4.0.154

在属性编辑器(Studio 右侧边栏)中更新默认属性。 你的组件将使用新的属性重新渲染。 这些属性不会保存到根文件——要保存,请使用saveDefaultProps()

🌐 Updates the default props in the Props Editor (in the right sidebar in the Studio).
Your component will be re-rendered with the new props.
The props will not be saved to the Root file - use saveDefaultProps() for that.

示例

🌐 Examples

Setting {color: 'green'} as the default props
import { updateDefaultProps } from "@remotion/studio"; updateDefaultProps({ compositionId: "my-composition", defaultProps: () => { return { color: "green", }; }, });

你可以访问当前未保存的默认属性,仅覆盖其中一部分(类似 reducer 风格):

🌐 You can access the current unsaved default props to only override part of it (reducer-style):

Accessing the current props
import { saveDefaultProps } from "@remotion/studio"; await saveDefaultProps({ compositionId: "my-composition", defaultProps: ({ unsavedDefaultProps }) => { return { ...unsavedDefaultProps, color: "green" }; }, });

如果你只想覆盖已保存的更改:

🌐 If you only want to override on top of the saved changes:

Accessing the saved props
import { updateDefaultProps } from "@remotion/studio"; updateDefaultProps({ compositionId: "my-composition", defaultProps: ({ savedDefaultProps }) => { return { ...savedDefaultProps, color: "green", }; }, });

如果你有一个 Zod 模式,你也可以访问它的运行时值:

🌐 If you have a Zod schema, you can also access its runtime value:

Save props from the Props Editor
import { updateDefaultProps } from "@remotion/studio"; updateDefaultProps({ compositionId: "my-composition", defaultProps: ({ schema, unsavedDefaultProps }) => { // Do something with the Zod schema return { ...unsavedDefaultProps, color: "red", }; }, });

要求

🌐 Requirements

为了使用此功能:

🌐 In order to use this function:

你需要在 Remotion Studio 内部。


Studio 必须正在运行(不能是静态部署)


zod 需要被安装。



否则,该函数将抛出异常。

🌐 Otherwise, the function will throw.

另请参阅

🌐 See also