🎥 Make videos programmatically with React
docs
Patric Salvisberg6ce8d695ec19
diff --git a/packages/docs/docs/data-fetching.md b/packages/docs/docs/data-fetching.mdindex 012d182bcd..52e50a9c4e 100644--- a/packages/docs/docs/data-fetching.md+++ b/packages/docs/docs/data-fetching.md@@ -299,9 +299,10 @@ This `abortSignal` is created by Remotion using the [`AbortController`](https://If you are making requests to an expensive API, you might want to only fire a request after the user has stopped typing for a while. You may use the following function for doing so:```tsx twoslash title="src/wait-for-no-input.ts"+import { getRemotionEnvironment } from "remotion";export const waitForNoInput = (signal: AbortSignal, ms: number) => {// Don't wait during rendering- if (getRemotionEnvironment() === "rendering") {+ if (getRemotionEnvironment().isRendering) {return Promise.resolve();}@@ -325,11 +326,11 @@ export const waitForNoInput = (signal: AbortSignal, ms: number) => {``````tsx twoslash title="src/MyComp.tsx" {4}-import { CalculateMetadataFunction } from "remotion";+import { CalculateMetadataFunction, getRemotionEnvironment } from "remotion";const waitForNoInput = (signal: AbortSignal, ms: number) => {// Don't wait during rendering- if (getRemotionEnvironment() === "rendering") {+ if (getRemotionEnvironment().isRendering) {return Promise.resolve();}diff --git a/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.md b/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.mdindex 191f53b97f..573fdaf8b6 100644--- a/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.md+++ b/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.md@@ -12,7 +12,7 @@ This is useful for attaching a `ref` to the [`<Video />`](/docs/video) tag.```tsx twoslashimport { forwardRef } from "react";import {- Experimental,+ getRemotionEnvironment,OffthreadVideo,RemotionOffthreadVideoProps,Video,@@ -23,7 +23,7 @@ const OffthreadWhileRenderingRefForwardingFunction: React.ForwardRefRenderFunctiRemotionOffthreadVideoProps> = (props, ref) => {const { imageFormat, ...otherProps } = props;- const isPlayer = Experimental.useIsPlayer();+ const isPlayer = getRemotionEnvironment().isPlayer;if (isPlayer) {return <Video ref={ref} {...otherProps}></Video>;diff --git a/packages/docs/docs/use-remotion-environment.md b/packages/docs/docs/use-remotion-environment.mdindex 7df17d6a39..bdc9a1b2e5 100644--- a/packages/docs/docs/use-remotion-environment.md+++ b/packages/docs/docs/use-remotion-environment.md@@ -4,15 +4,15 @@ id: get-remotion-environmentcrumb: "API"----With this hook, you can retrieve information on the current Remotion Environment.+With this `getRemotionEnvironment()`, you can retrieve information on the current Remotion Environment.`useRemotionEnvironment` returns an object with the following properties:-- `isStudio`: Indicates if one is currently in the studio.+- `isStudio`: Indicates if you are currently in the studio.- `ìsRendering`: Tells if one is currently in a render.-- `isPlayer`: Tells if one is in the Player.+- `isPlayer`: Indicates if you are in the Player.- `isProduction`: Based on your .env file, tells if you are in production or in development-This can be useful if you want components to compute some value differently based on the environment you are in.+This can be useful if you want components to compute some values differently based on the environment you are in.### Example@@ -21,19 +21,24 @@ import React from "react";import { getRemotionEnvironment } from "remotion";export const MyComp: React.FC = () => {- const { isStudio, isRendering, isPlayer, isProduction } =- getRemotionEnvironment();- console.log(isStudio); // false;- console.log(isRendering); // true- console.log(isPlayer); // false- console.log(isProduction); //true+ const { isStudio, isPlayer } = getRemotionEnvironment();++ if (isStudio) {+ return <div>I'm in the Studio!</div>;+ }++ if (isPlayer) {+ return <div>I'm in the Player!</div>;+ }return <div>Hello World!</div>;};```+A more realistic use case: In the Remotion Studio you might want to debounce a request, but not during rendering. See [debouncing requests](/docs/data-fetching#debouncing-requests) for an indepth explanation.+## See also- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/get-environment.ts)- [useVideoConfig()](/docs/use-video-config)-- [`<Sequence />`](/docs/sequence)+- [`<OffthreadVideo/> while rendering`](/docs/miscellaneous/snippets/offthread-video-while-rendering)