This is my code for a modal form I'm using and I wanted to use my function to console.log, but I'm not sure how to change the state in this.set.state? Any help is appreciated since Im very new to react. The variable st is just the string it takes in each time
interface State {
name: string;
email: string;
amt: string;
}
interface Props {
isOpen: boolean;
handleClose: () => void;
handleSendRequest: (values: State) => void;
}
export default class FormDialog extends React.Component<Props, State> {
state = { name: "", email: "", amt: "" };
onChange = ((st: string) => (event: any) => {
const newObject: any = {};
newObject[st] = event.target.value;
this.setState({ State: newObject[st] }); //this part im struggling with
}).bind(this);
render() {
const { isOpen, handleClose, handleSendRequest } = this.props;
return (
<Dialog
open={isOpen}
onClose={handleClose}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">Send Money Request</DialogTitle>
<DialogContent>
<TextField
autoFocus
margin="dense"
id="standard-read-only-input"
name="name"
label="Contact Name"
defaultValue="John"
onChange={this.onChange("name")}
/>