Skip to content

🎥 Make videos programmatically with React

add test in example

Jonny Burger7f87c522b18f
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 7466d2eed2..3191716149 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -65,6 +65,7 @@ import {VideoSpeed} from './VideoSpeed';
import {VideoTesting} from './VideoTesting';
import {WarpDemoOuter} from './WarpText';
import {WarpDemo2} from './WarpText/demo2';
+import {WatchStaticDemo} from './watch-static';
if (alias !== 'alias') {
throw new Error('should support TS aliases');
@@ -583,13 +584,17 @@ export const Index: React.FC = () => {
/>
</Folder>
<Folder name="features">
- <Composition
+ <Still
id="mdx-test"
lazyComponent={() => import('./MdxTest')}
width={1080}
height={1080}
- fps={30}
- durationInFrames={30 * 30}
+ />
+ <Still
+ id="watch-static"
+ component={WatchStaticDemo}
+ width={1080}
+ height={1080}
/>
<Composition
id="color-interpolation"
diff --git a/packages/example/src/watch-static.tsx b/packages/example/src/watch-static.tsx
new file mode 100644
index 0000000000..36efa3e99a
--- /dev/null
+++ b/packages/example/src/watch-static.tsx
@@ -0,0 +1,33 @@
+import React, {useCallback, useEffect, useState} from 'react';
+import {AbsoluteFill, staticFile, watchStaticFile} from 'remotion';
+
+export const WatchStaticDemo: React.FC = () => {
+ const [content, setContent] = useState<string | null>(null);
+
+ const fetchStaticFile = useCallback(async () => {
+ const txt = await fetch(staticFile('example.txt'));
+ const json = await txt.text();
+ setContent(json);
+ }, []);
+
+ useEffect(() => {
+ fetchStaticFile();
+ }, [fetchStaticFile]);
+
+ useEffect(() => {
+ const {cancel} = watchStaticFile('example.txt', (newFile) => {
+ console.log(newFile);
+ fetchStaticFile();
+ });
+
+ return () => {
+ cancel();
+ };
+ }, [fetchStaticFile]);
+
+ return (
+ <AbsoluteFill>
+ <h1 style={{fontSize: 100, fontFamily: 'sans-serif'}}>{content}</h1>
+ </AbsoluteFill>
+ );
+};