---
title: "Editable"
slug: editable
category: component
type: examples
version: 20.0.0
tokens: 1129
source: https://ovh.github.io/design-system/v20.0.0/llms/react-components-editable--examples.txt
---
# Editable
## Default
```tsx
{
const [value, setValue] = useState('Double click to edit');
const bufferValue = useRef(value);
return (
bufferValue.current = value }
onSubmit={ () => setValue(bufferValue.current) }>
{ value || Empty value }
bufferValue.current = e.target.value } />
);
}
```
## Controlled
```tsx
{
const [displayValue, setDisplayValue] = useState('Double click to edit');
const [value, setValue] = useState(displayValue);
return (
setValue(displayValue) }
onSubmit={ () => setDisplayValue(value) }>
{ displayValue || Empty value }
setValue(e.target.value) }
value={ value } />
);
}
```
## Custom Actions
```tsx
{
const [value, setValue] = useState('Double click to edit');
const bufferValue = useRef(value);
return (
bufferValue.current = value }
onSubmit={ () => setValue(bufferValue.current) }>
{ value || Empty value }
bufferValue.current = e.target.value } />
{
({ editing }) => (
editing
? <>
>
:
)
}
);
}
```
## Complex Form Element
```tsx
{
const [displayValue, setDisplayValue] = useState('');
const [accountValue, setAccountValue] = useState('');
const [domainValue, setDomainValue] = useState('');
function onCancel(): void {
const [account, domain] = displayValue.split('@ovhcloud');
setAccountValue(account || '');
setDomainValue(domain || '');
}
return (
setDisplayValue(`${accountValue}@ovhcloud${domainValue}`) }>
{ displayValue || Account name }
setAccountValue(e.target.value) }
pattern="^([a-zA-Z0-9]|([._\-](?![._\-])))*[a-zA-Z0-9]$"
placeholder="Account name"
value={ accountValue } />
@ovhcloud
);
}
```