Skip to main content

reorderJsxNode()v4.0.528

Moves a JSX element before or after a sibling.

warning

Draft API: This API is experimental and may change.

reorder-jsx-node.ts
import {reorderJsxNode, type CodemodProject, type JsxNodeReference} from '@remotion/codemods'; declare const project: CodemodProject; declare const node: JsxNodeReference; declare const target: JsxNodeReference; const result = await reorderJsxNode({ 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

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also