replaceJsxElementWithSource()v4.0.544
Replaces a JSX node with saved source and restores its imports.
warning
Draft API: This API is experimental and may change.
replace-jsx-element-with-source.tsimport {replaceJsxElementWithSource , typeCodemodProject , typeNodeReference } from '@remotion/codemods'; declare constproject :CodemodProject ; declare constnode :NodeReference ; constresult =replaceJsxElementWithSource ({project ,node ,source : '<Scene />',importStatements : ["import {Scene} from './Scene';"], });console .log (result .changes );
Options
project
An in-memory CodemodProject.
node
The target NodeReference.
source
Source containing one JSX element.
importStatements
Import declarations required by the replacement. Missing bindings are merged into compatible existing imports. Unused imports from the replaced node are removed.
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.
logLine
The replaced node'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
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||