I am working on a shared component, which is an input textarea
The component is:
class TextBox extends React.Component {
constructor(props) {
...
const value = this.props.value;
this.state = {
value: value
}
}
handleChange(e, v) {
console.log("event: ", e);
this.setState({value: e.target.value}, () => {this.props.handleChange(e, v)});
}
render() {
const {
name
} = this.props;
const {
value
} = this.state;
return (
<div>
<h2>{name}</h2>
<textarea
value={value}
onChange={this.handleChange}
/>
</div>
);
}
}
Using this component:
const [comment, setComment] = useState('');
const handleChange = useCallback((e, v) => {
setComment(v);
}, [comment]);
....
<TextBox
name="comment"
value={comment}
handleChange={handleChange}
/>
The console log shows event.target.value is undefined I have no idea why, can someone help? Thanks in advance
===update=== Thank you all! The problem is fixed