Skip to main content

watchStaticFile()v4.0.144

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

🌐 Watches for changes in a specific static file and invokes a callback function when the file changes, enabling dynamic updates in your Remotion projects.

note

此 API 正从 remotion 包中移出。
建议优先使用此 API,而不是旧的 API。

note

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

示例

🌐 Example

example.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();

参数

🌐 Arguments

接受两个参数并返回一个可以用来 cancel 事件监听器的函数。

🌐 Takes two arguments and returns a function that can be used to cancel the event listener.

filename

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

🌐 A name of the file in /public folder to watch for changes.

callback

当文件被修改时将调用的回调函数。作为参数,会传入 StaticFilenull

🌐 A callback function that will be called when the file is modified. As an argument, a StaticFile or null is passed.

另请参阅

🌐 See also