Skip to main content

setCompositionDefaultProps()v4.0.528

Replaces a composition's statically readable default props or adds them when missing.

warning

Draft API: This API is experimental and may change.

set-composition-default-props.ts
import {setCompositionDefaultProps, type CodemodProject} from '@remotion/codemods'; declare const project: CodemodProject; const result = setCompositionDefaultProps({ project, compositionFile: 'src/Root.tsx', compositionId: 'MyComposition', defaultProps: {title: 'Hello', backgroundColor: '#ffffff'}, }); console.log(result);

Computed default props and props potentially overridden by a spread are rejected. The component implementation is unchanged.

Options​

project​

An in-memory CodemodProject. The input project is not mutated.

compositionFile​

The project file containing the <Composition> or <Still> registration. Static IDs, named import aliases, and namespace imports from remotion are supported.

compositionId​

The static ID of the composition to edit.

defaultProps​

The complete replacement object of serializable prop values. This replaces the object rather than merging it.

enumPaths?​

Paths whose values should be written with an as const assertion to preserve literal types. For example, [['mode']] writes a string mode value as 'value' as const. Use '[]' to match array indices and '{}' to match object keys, such as [['items', '[]', 'mode']]. By default, no assertions are added.

Return value​

Returns an object with the following properties.

changes​

An array of {filePath, previousContents, nextContents} file changes. A null content value indicates a created or deleted file.

nodePathRemappings​

An array of {filePath, oldNodePath, newNodePath} mappings. A null old path indicates an insertion; a null new path indicates removal. Apply these mappings to references from the input project. See node references.

updatedNode​

The composition registration's node reference.

logLine​

The one-based line of the composition registration in the input source.

Errors​

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

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​