Skip to main content

saveDefaultProps()v4.0.147

保存defaultProps以便将composition的默认属性保存回根文件
如果您只想在Props Editor(Studio中的右侧边栏)中更新默认属性而不将其保存到根文件中,请使用updateDefaultProps()

Examples

将{color: 'green'}保存到Root.tsx
tsx
import { saveDefaultProps } from "@remotion/studio";
 
await saveDefaultProps({
compositionId: "my-composition",
defaultProps: () => {
return {
color: "green",
};
},
});
将{color: 'green'}保存到Root.tsx
tsx
import { saveDefaultProps } from "@remotion/studio";
 
await saveDefaultProps({
compositionId: "my-composition",
defaultProps: () => {
return {
color: "green",
};
},
});

您可以访问保存的默认属性以仅覆盖其中的一部分(类似于reducer风格):

访问保存的默认属性
tsx
import { saveDefaultProps } from "@remotion/studio";
 
await saveDefaultProps({
compositionId: "my-composition",
defaultProps: ({ savedDefaultProps }) => {
return {
...savedDefaultProps,
color: "green",
};
},
});
访问保存的默认属性
tsx
import { saveDefaultProps } from "@remotion/studio";
 
await saveDefaultProps({
compositionId: "my-composition",
defaultProps: ({ savedDefaultProps }) => {
return {
...savedDefaultProps,
color: "green",
};
},
});

如果您在Props Editor(Studio中的右侧边栏)中修改了props,则还可以从那里访问未保存的props,例如保存它们:

从Props Editor保存props
tsx
import { saveDefaultProps } from "@remotion/studio";
 
await saveDefaultProps({
compositionId: "my-composition",
defaultProps: ({ unsavedDefaultProps }) => {
return unsavedDefaultProps;
},
});
从Props Editor保存props
tsx
import { saveDefaultProps } from "@remotion/studio";
 
await saveDefaultProps({
compositionId: "my-composition",
defaultProps: ({ unsavedDefaultProps }) => {
return unsavedDefaultProps;
},
});

如果您有一个Zod模式,还可以访问其运行时值:

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

要求

为了使用此功能:

您需要在Remotion Studio中。


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


必须安装zod



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

另请参阅