reorderJsxNode()v4.0.528
Moves a JSX element before or after a sibling.
Draft API: This API is experimental and may change.
reorder-jsx-node.tsimport {reorderJsxNode , typeCodemodProject , typeJsxNodeReference } from '@remotion/codemods'; declare constproject :CodemodProject ; declare constnode :JsxNodeReference ; declare consttarget :JsxNodeReference ; constresult = awaitreorderJsxNode ({project ,node ,target ,position : 'before', });console .log (result );
Both nodes must be direct JSX siblings in the same file. This changes source order and stacking order, not timeline timing. Moving into a different parent or file is unsupported.
Options
project
An in-memory CodemodProject. The input project is not mutated.
node
A JsxNodeReference from getJsxNodes() or a previous operation. It contains filePath and nodePath.
target
The sibling node reference to position relative to.
position
Either before or after.
Return value
A promise resolving to an object with the following properties.
project
The updated project. Unchanged files and extra project fields are preserved.
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 moved node's reference in the new project.
Errors
Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.
Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||