getRemotionEnvironment()v4.0.25
使用 getRemotionEnvironment() 函数,你可以获取有关当前 Remotion 环境的信息。
🌐 With the getRemotionEnvironment() function, you can retrieve information about the current Remotion Environment.
info
考虑改用 useRemotionEnvironment() 钩子,因为它对浏览器渲染场景是面向未来的。
它返回一个具有以下属性的对象:
isStudio:该函数是否在 Remotion Studio 中被调用。isRendering:这个函数是否在渲染中被调用。也可以在calculateMetadata()函数中使用。isPlayer:当前页面是否挂载了<Player>。isReadOnlyStudio:无论是在静态部署的工作室,还是@remotion/studioAPI 无法使用的情况下(从 v4.0.238 可用)isClientSideRendering:函数是否在客户端渲染上下文中被调用(从 v4.0.344 起可用)
如果你希望组件或函数根据环境表现不同,这可能会很有用。
🌐 This can be useful if you want components or functions to behave differently depending on the environment.
示例
🌐 Example
import React from 'react';
import {getRemotionEnvironment } from 'remotion';
export const MyComp : React .FC = () => {
const {isStudio , isPlayer , isRendering } = getRemotionEnvironment ();
if (isStudio ) {
return <div >I'm in the Studio!</div >;
}
if (isPlayer ) {
return <div >I'm in the Player!</div >;
}
if (isRendering ) {
return <div >I'm Rendering</div >;
}
return <div >Hello World!</div >;
};一个更实际的使用场景:你可能希望在 Remotion Studio 中编辑时对请求进行防抖处理,但在渲染时不进行防抖。参见:请求防抖
🌐 A more realistic use case: You might want to debounce a request during editing in the Remotion Studio, but not during rendering. See: debouncing requests
兼容性
🌐 Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||
All false | All false | All false | Use useRemotionEnvironment() | ||||||
另请参阅
🌐 See also