useCommittableValue Function
Custom React hook that provides to commit or cancel value changes by editor using
Enter or Escape keys.
Example usage:
function MyValueEditor({ initialValue, ...editorProps }: Props) {
  const { value, onChange, onKeyDown, commit, cancel } = useCommittableValue({
    initialValue,
    onCommit: (newValue) => {
      // commit new value
    }
    onCancel: () => {
      // restore to initial value or close editor
    }
  })
  return <div onKeyDown={onKeydown}>
    <Editor
      {...editorProps}
      value={value}
      onChange={onChange}
      commit={commit}
      cancel={cancel}
    />
  </div>
}
useCommittableValue(__namedParameters: UseCommittableValueProps): { cancel: () => void, commit: () => void, onChange: (newValue?: Value) => void, onKeydown: (e: React.KeyboardEvent<Element>) => void, value: undefined | Value }
| Parameter | Type | Description | 
|---|---|---|
| __namedParameters | UseCommittableValueProps | 
Returns - { cancel: () => void, commit: () => void, onChange: (newValue?: Value) => void, onKeydown: (e: React.KeyboardEvent<Element>) => void, value: undefined | Value }
Defined in
Last Updated: 24 June, 2025
Found something wrong, missing, or unclear on this page? Raise an issue in our repo.