Skip to content

🎥 Make videos programmatically with React

Use compileCode directly instead of shallow wrapping via useCodeCompiler.ts

ASchwad3ea0c1c04d53
diff --git a/packages/template-prompt-to-motion-graphics/src/hooks/useAnimationState.ts b/packages/template-prompt-to-motion-graphics/src/hooks/useAnimationState.ts
index 07d11331f3..60b8c8103a 100644
--- a/packages/template-prompt-to-motion-graphics/src/hooks/useAnimationState.ts
+++ b/packages/template-prompt-to-motion-graphics/src/hooks/useAnimationState.ts
@@ -1,7 +1,10 @@
"use client";
import { useState, useEffect, useCallback } from "react";
-import { useCodeCompiler, CompilationResult } from "./useCodeCompiler";
+import {
+ compileCode as compile,
+ type CompilationResult,
+} from "../remotion/compiler";
export interface AnimationState {
code: string;
@@ -11,7 +14,6 @@ export interface AnimationState {
}
export function useAnimationState(initialCode: string = "") {
- const { compile } = useCodeCompiler();
const [state, setState] = useState<AnimationState>({
code: initialCode,
Component: null,
@@ -20,21 +22,18 @@ export function useAnimationState(initialCode: string = "") {
});
// Compile code when it changes (with debouncing handled by caller)
- const compileCode = useCallback(
- (code: string) => {
- setState((prev) => ({ ...prev, isCompiling: true }));
-
- const result: CompilationResult = compile(code);
-
- setState((prev) => ({
- ...prev,
- Component: result.Component,
- error: result.error,
- isCompiling: false,
- }));
- },
- [compile]
- );
+ const compileCode = useCallback((code: string) => {
+ setState((prev) => ({ ...prev, isCompiling: true }));
+
+ const result: CompilationResult = compile(code);
+
+ setState((prev) => ({
+ ...prev,
+ Component: result.Component,
+ error: result.error,
+ isCompiling: false,
+ }));
+ }, []);
// Update code and trigger compilation
const setCode = useCallback((newCode: string) => {
diff --git a/packages/template-prompt-to-motion-graphics/src/hooks/useCodeCompiler.ts b/packages/template-prompt-to-motion-graphics/src/hooks/useCodeCompiler.ts
deleted file mode 100644
index 60d8198158..0000000000
--- a/packages/template-prompt-to-motion-graphics/src/hooks/useCodeCompiler.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-"use client";
-
-import { useCallback } from "react";
-import {
- compileCode,
- type CompilationResult,
-} from "../remotion/compiler";
-
-export type { CompilationResult };
-
-export function useCodeCompiler() {
- const compile = useCallback(
- (code: string): CompilationResult => compileCode(code),
- [],
- );
-
- return { compile };
-}