Skip to main content

watchStaticFile()v4.0.144

监视特定静态文件的更改,并在文件更改时调用回调函数,从而实现在您的 Remotion 项目中进行动态更新。

note

此 API 正在从 remotion 包中移动。
请优先使用此 API 而不是旧的 API。

note

此功能仅在 Remotion Studio 环境中可用。在播放器中,事件将永远不会触发。

示例

example.tsx
tsx
import { StaticFile, watchStaticFile } from "@remotion/studio";
 
// Watch for changes in a specific static file
const { cancel } = watchStaticFile(
"your-static-file.jpg",
(newData: StaticFile | null) => {
if (newData) {
console.log(`File ${newData.name} has been added or modified.`);
} else {
console.log("File has been deleted.");
}
},
);
 
// To stop watching for changes, call the cancel function
cancel();
example.tsx
tsx
import { StaticFile, watchStaticFile } from "@remotion/studio";
 
// Watch for changes in a specific static file
const { cancel } = watchStaticFile(
"your-static-file.jpg",
(newData: StaticFile | null) => {
if (newData) {
console.log(`File ${newData.name} has been added or modified.`);
} else {
console.log("File has been deleted.");
}
},
);
 
// To stop watching for changes, call the cancel function
cancel();

参数

接受两个参数并返回一个可用于取消事件监听器的函数。

filename

要监视更改的/public文件夹中的文件名。

callback

当文件被修改时将调用的回调函数。作为参数传递了一个StaticFilenull

另请参阅