Skip to main content

replaceNodeChild()v4.0.544

Replaces a node's single JSX child with an element and records the original source and imports for restoration.

warning

Draft API: This API is experimental and may change.

replace-node-child.ts
import {replaceNodeChild, type CodemodProject, type NodeReference, createElement} from '@remotion/codemods'; declare const project: CodemodProject; declare const node: NodeReference; const result = replaceNodeChild({ project, node, element: createElement({component: 'Video', importPath: '@remotion/media', props: {src: 'https://example.com/scene.mp4'}}), }); console.log(result.changes);

Options​

project​

An in-memory CodemodProject.

node​

The target NodeReference.

element​

The replacement created with createElement(). The target node must contain exactly one meaningful JSX child. Its surrounding node is preserved.

Return value​

An object with the following properties.

changes​

File changes to apply with applyCodemodChanges(). The input project is not mutated.

nodePathRemappings​

Mappings from the original node paths to their new paths. See node references.

replacedSource​

The original child JSX source.

replacedImports​

Import declarations used by the original child. Unused bindings are removed from the edited source.

sceneImportSource​

The module containing the original child's component, or null.

logLine​

The original child's source line.

Errors​

Throws when the target cannot be resolved or the requested edit is invalid. Failed edits leave the input project unchanged.

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​