{"record":{"id":"2e73c4bf65041638","repo":"remotion-dev/remotion","slug":"usecurrentframe-can-only-be-called-inside-a-comp","errorCode":null,"errorMessage":"useCurrentFrame() can only be called inside a component that was registered as a composition. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions","messagePattern":"useCurrentFrame\\(\\) can only be called inside a component that was registered as a composition\\. See https://www\\.remotion\\.dev/docs/the-fundamentals#defining-compositions","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/use-current-frame.ts","lineNumber":22,"sourceCode":"import {useTimelinePosition} from './timeline-position-state.js';\nimport {useRemotionEnvironment} from './use-remotion-environment.js';\n\n/*\n * @description Retrieves the current frame of the video within a component. Frames are 0-indexed, and if the component is wrapped in a `<Sequence>`, it returns the frame relative to when the Sequence starts.\n * @see [Documentation](https://www.remotion.dev/docs/use-current-frame)\n */\nexport const useCurrentFrame = (): number => {\n\tconst canUseRemotionHooks = useContext(CanUseRemotionHooks);\n\tconst env = useRemotionEnvironment();\n\n\tif (!canUseRemotionHooks) {\n\t\tif (env.isPlayer) {\n\t\t\tthrow new Error(\n\t\t\t\t`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`,\n\t\t\t);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`useCurrentFrame() can only be called inside a component that was registered as a composition. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions`,\n\t\t);\n\t}\n\n\tconst frame = useTimelinePosition();\n\tconst context = useContext(SequenceContext);\n\n\tconst contextOffset = context\n\t\t? context.cumulatedFrom + context.relativeFrom\n\t\t: 0;\n\n\treturn frame - contextOffset;\n};\n","sourceCodeStart":4,"sourceCodeEnd":36,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/use-current-frame.ts#L4-L36","documentation":"useCurrentFrame() checks the CanUseRemotionHooks context before reading the timeline. When that context is false and the environment is NOT the Player (i.e. Studio/CLI/SSR), this message fires, telling you the calling component was never registered as a <Composition> component.","triggerScenarios":"Calling useCurrentFrame() in a component that is rendered standalone (plain React app, Storybook, unit test) without being registered via <Composition component={...}> or wrapped in a <Player>.","commonSituations":"Mounting a Remotion component in a design tool or test harness; importing a composition component into a Next.js/CRA page; SSR pre-rendering a component that uses Remotion hooks.","solutions":["Register the component via <Composition component={MyComp} .../> in your Remotion root.","For previews outside Remotion, wrap the component in a <Player> instead of rendering it directly.","Remove the useCurrentFrame() call from components that are not part of a composition (pass frame as a prop)."],"exampleFix":"// before\nReactDOM.render(<MyComp />, root);\n\n// after\nReactDOM.render(\n  <Player component={MyComp} durationInFrames={30} fps={30} width={640} height={360} />,\n  root,\n);","handlingStrategy":"validation","validationCode":"// Register the component as a Composition, or wrap it in a Player for standalone use\nimport {Player} from '@remotion/player';\n\nrender(\n  <Player\n    component={MyComp}\n    durationInFrames={30}\n    fps={30}\n    width={640}\n    height={360}\n  />,\n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register every component that calls Remotion hooks via <Composition>.","For previews/tests, wrap such components in a <Player>.","Do not import composition components into plain React apps."],"tags":["react","context","hook","composition","use-current-frame"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}