Reorder editable rows
A list editor needs to move a row upward or downward without replacing the entire form state.
Conform · Pipe
form.reorder creates button props for moving an item within an array field. Provide the list name and the item’s current and destination indexes.
form.reorder provides button props for changing the order of items in an array field. Pass the array field name, the item's current index, and its destination index; the resulting intent is handled when the form control is used.
form.reorder.getButtonProps({ name, from, to })| Name | Type | Description |
|---|---|---|
name | string | Name of the array field. |
from | number | Current index of the item. |
to | number | Target index to move the item to. |
void
name to the array field being reordered.from for the item’s current position.to for the destination position.const form = useForm();
const fields = form.getFieldset();
return (
<form {...form.props}>
{fields.tasks.getFieldList().map((task, index) => (
<div key={task.key}>
<input name={task.name} />
<button {...form.reorder.getButtonProps({
name: fields.tasks.name,
from: index,
to: 0,
})}>
Move to top
</button>
</div>
))}
</form>
);Adds a button that moves the selected array item to index 0 when activated.
A list editor needs to move a row upward or downward without replacing the entire form state.
A task manager lets users promote one task to the first position.
A settings screen lets users arrange preferences by priority.
Use form.reorder.getButtonProps on a button and provide name, from, and to. The name identifies the array field, while from and to identify the current and target positions.
Follow-up: How would you move an item to the end? Pass the array field name, its current index as from, and the final array index as to.
The name option must refer to the array field whose items are being reordered. The from option is the current item index, and to is the destination index.
Follow-up: What should be checked when a reorder button moves the wrong item? Verify that the rendered item index and the submitted array-field name match the intended list.
Reordering is exposed as a form intent rather than requiring a custom submission format. Applying the generated props to a button lets Conform serialize the requested reorder operation for the form.
Follow-up: Which other form operations use the same intent approach? The documentation lists validating, resetting, updating, inserting, removing, and reordering as form actions.
useIntentform.insertform.removeform.updateIntent button