【发布时间】:2020-05-22 18:07:44
【问题描述】:
这是我正在使用的模态表单的代码,我想将我的函数用于 console.log,但我不确定如何更改 this.set.state 中的状态?任何帮助表示赞赏,因为我很新反应。变量st就是每次传入的字符串
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")}
/>
【问题讨论】:
标签: reactjs typescript