Update snippet descriptions
This commit is contained in:
@ -3,28 +3,26 @@ title: TextArea
|
||||
tags: components,input,beginner
|
||||
---
|
||||
|
||||
Renders a `<textarea>` element that uses a callback function to pass its value to the parent component.
|
||||
Renders an uncontrolled `<textarea>` element that uses a callback function to pass its value to the parent component.
|
||||
|
||||
- Use object destructuring to set defaults for certain attributes of the `<textarea>` element.
|
||||
- Render a `<textarea>` element with the appropriate attributes and use the `callback` function in the `onChange` event to pass the value of the textarea to the parent.
|
||||
- Use the `defaultValue` passed down from the parent as the uncontrolled input field's initial value.
|
||||
- Use the `onChange` event to fire the `onValueChange` callback and send the new value to the parent.
|
||||
|
||||
```jsx
|
||||
const TextArea = ({
|
||||
callback,
|
||||
cols = 20,
|
||||
rows = 2,
|
||||
disabled = false,
|
||||
readOnly = false,
|
||||
placeholder = ''
|
||||
defaultValue,
|
||||
onValueChange,
|
||||
...rest
|
||||
}) => {
|
||||
return (
|
||||
<textarea
|
||||
cols={cols}
|
||||
rows={rows}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
placeholder={placeholder}
|
||||
onChange={({ target: { value } }) => callback(value)}
|
||||
defaultValue={defaultValue}
|
||||
onChange={({ target: { value } }) => onValueChange(value)}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@ -32,7 +30,10 @@ const TextArea = ({
|
||||
|
||||
```jsx
|
||||
ReactDOM.render(
|
||||
<TextArea placeholder="Insert some text here..." callback={val => console.log(val)} />,
|
||||
<TextArea
|
||||
placeholder="Insert some text here..."
|
||||
onValueChange={val => console.log(val)}
|
||||
/>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user