saveDefaultProps()v4.0.147
将 defaultProps 的 composition 保存回 root file。
如果你只想在 Props 编辑器(Studio 右侧边栏)中更新默认属性,而不将它们保存到 root 文件中,请使用 updateDefaultProps()。
🌐 Saves the defaultProps for a composition back to the root file.
If you just want to update the default props in the Props Editor (right sidebar in the Studio) without saving them to the root file, use updateDefaultProps().
示例
🌐 Examples
Saving {color: 'green'} to Root.tsximport {saveDefaultProps } from "@remotion/studio"; awaitsaveDefaultProps ({compositionId : "my-composition",defaultProps : () => { return {color : "green", }; }, });
你可以访问保存的默认属性,仅覆盖其中的一部分(类似 reducer 的方式):
🌐 You can access the saved default props to only override part of it (reducer-style):
Accessing the saved default propsimport {saveDefaultProps } from "@remotion/studio"; awaitsaveDefaultProps ({compositionId : "my-composition",defaultProps : ({savedDefaultProps }) => { return { ...savedDefaultProps ,color : "green", }; }, });
如果你在 Props 编辑器(Studio 的右侧边栏)中修改了属性,你也可以从那里访问未保存的属性,例如进行保存:
🌐 If you modified props in the Props Editor (right sidebar in the Studio), you can also access the unsaved props from there, and for example save them:
Save props from the Props Editorimport {saveDefaultProps } from "@remotion/studio"; awaitsaveDefaultProps ({compositionId : "my-composition",defaultProps : ({unsavedDefaultProps }) => { returnunsavedDefaultProps ; }, });
如果你有一个 Zod 模式,你也可以访问它的运行时值:
🌐 If you have a Zod schema, you can also access its runtime value:
Save props from the Props Editorimport {saveDefaultProps } from "@remotion/studio"; awaitsaveDefaultProps ({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