Skip to content

🎥 Make videos programmatically with React

demo back on homepage

Jonny Burgera0351c8b0923
diff --git a/packages/docs/src/components/Demo/Demo.tsx b/packages/docs/src/components/Demo/Demo.tsx
index f39f64af83..379d8b177e 100644
--- a/packages/docs/src/components/Demo/Demo.tsx
+++ b/packages/docs/src/components/Demo/Demo.tsx
@@ -1,23 +1,22 @@
import {useColorMode} from '@docusaurus/theme-common';
import {Player} from '@remotion/player';
import React, {useEffect, useState} from 'react';
-import {HomepageVideoComp} from '../../remotion/HomepageVideo/Comp';
-import type {Location} from '../../remotion/HomepageVideo/types';
+import type {LocationAndTrending} from '../../remotion/HomepageVideo/Comp';
+import {
+ HomepageVideoComp,
+ getDataAndProps,
+} from '../../remotion/HomepageVideo/Comp';
import {ActionRow} from './ActionRow';
export const Demo: React.FC = () => {
const {colorMode} = useColorMode();
- const [location, setLocation] = useState<Location | null>(null);
+ const [location, setLocationAndTrending] =
+ useState<LocationAndTrending | null>(null);
useEffect(() => {
- fetch('https://bugs-git-homepage-player-remotion.vercel.app/api/location')
- .then((res) => res.json())
- .then((data: Location) => {
- setLocation(data);
- })
- .catch((err) => {
- console.error(err);
- });
+ getDataAndProps().then((data) => {
+ setLocationAndTrending(data);
+ });
}, []);
const strokeColor = colorMode === 'dark' ? 'gray' : 'black';
@@ -28,28 +27,30 @@ export const Demo: React.FC = () => {
<br />
<br />
<h1>Try it out</h1>
- <Player
- component={HomepageVideoComp}
- compositionWidth={640}
- compositionHeight={360}
- durationInFrames={120}
- fps={30}
- autoPlay
- controls
- clickToPlay={false}
- style={{
- border: '2px solid ' + strokeColor,
- borderBottom: '4px solid ' + strokeColor,
- borderRadius: 8,
- width: '100%',
- }}
- inputProps={{
- theme: colorMode,
- location,
- trending: null,
- }}
- loop
- />
+ {location ? (
+ <Player
+ component={HomepageVideoComp}
+ compositionWidth={640}
+ compositionHeight={360}
+ durationInFrames={120}
+ fps={30}
+ autoPlay
+ controls
+ clickToPlay={false}
+ style={{
+ border: '2px solid ' + strokeColor,
+ borderBottom: '4px solid ' + strokeColor,
+ borderRadius: 8,
+ width: '100%',
+ }}
+ inputProps={{
+ theme: colorMode,
+ ...location,
+ }}
+ loop
+ />
+ ) : null}
+
<ActionRow />
</div>
);
diff --git a/packages/docs/src/remotion/HomepageVideo/Comp.tsx b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
index 0c27e5523d..dc53e72cbf 100644
--- a/packages/docs/src/remotion/HomepageVideo/Comp.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
@@ -5,12 +5,27 @@ import {z} from 'zod';
import {Cards} from './Card';
import type {Location} from './types';
+export type LocationAndTrending = {
+ location: Location;
+ trending: string[];
+};
+
+export const getDataAndProps = async () => {
+ const trending = (await fetch('https://bugs.remotion.dev/trending')
+ .then((res) => res.json())
+ .then((data) => data.repos.slice(0, 3))) as string[];
+
+ const location = (await fetch(
+ 'https://bugs-git-homepage-player-remotion.vercel.app/api/location',
+ ).then((res) => res.json())) as Location;
+
+ return {trending, location};
+};
+
export const calculateMetadata: CalculateMetadataFunction<
z.infer<typeof schema> & Props
> = async ({props}) => {
- const trending = await fetch('https://bugs.remotion.dev/trending')
- .then((res) => res.json())
- .then((data) => data.repos.slice(0, 3));
+ const {trending, location} = await getDataAndProps();
return {
durationInFrames: 120,
@@ -20,6 +35,7 @@ export const calculateMetadata: CalculateMetadataFunction<
props: {
...props,
trending,
+ location,
},
};
};