Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用react中的物料UI将一个文本字段的值传递到另一个文本字段?_Javascript_Reactjs_Material Ui_State - Fatal编程技术网

Javascript 如何使用react中的物料UI将一个文本字段的值传递到另一个文本字段?

Javascript 如何使用react中的物料UI将一个文本字段的值传递到另一个文本字段?,javascript,reactjs,material-ui,state,Javascript,Reactjs,Material Ui,State,我想将内容从一个文本字段(嵌入对话框窗口)传输到另一个文本字段(未嵌入) 当前结果是“对象”(而不是文本字段值)。你知道为什么它不起作用吗 我在一个功能组件中创建了两种不同的状态。函数“setOriginalTextValue”应将一种状态的值转移到另一种状态: export default function FormDialog() { const [value, setValue] = React.useState(); const [dialogValue, setDialogVa

我想将内容从一个文本字段(嵌入对话框窗口)传输到另一个文本字段(未嵌入)

当前结果是“对象”(而不是文本字段值)。你知道为什么它不起作用吗

我在一个功能组件中创建了两种不同的状态。函数“setOriginalTextValue”应将一种状态的值转移到另一种状态:

export default function FormDialog() {
  const [value, setValue] = React.useState();
  const [dialogValue, setDialogValue] = React.useState();

  const [open, setOpen] = React.useState(false);

  const handleClickOpen = () => {
    setOpen(true);
  };

  const handleClose = () => {
    setOpen(false);
  };

  const handleChange = (event) => {
    setValue({
      value: event.target.value,
    });
  };

  const handleDialogValueChange = (event) => {
    setDialogValue({
      dialogValue: event.target.value,
    });
  };

  const setOriginalTextValue = () => {
    setValue({
      value: dialogValue,
    });
  };

  return (
    <div>
      <Button variant="text" color="inherit">
        <TextField
          id="outlined-multiline-static"
          label="Frage"
          multiline
          onClick={handleClickOpen}
          rows={4}
          value={value}
          placeholder="hello"
          onChange={handleClickOpen}
          variant="outlined"
          style={{
            backgroundColor: "white",
          }}
        />
      </Button>
      <Dialog
        open={open}
        onClose={handleClose}
        onExit={setOriginalTextValue}
        aria-labelledby="form-dialog-title"
      >
        <DialogTitle id="form-dialog-title">Subscribe</DialogTitle>
        <DialogContent>
          <DialogContentText>Please type the text in here</DialogContentText>
          <TextField
            autoFocus
            margin="dense"
            id="name"
            label="ChatbotTexxt"
            multiline
            rows={4}
            onChange={handleDialogValueChange}
            fullWidth
            onExit={console.log("the dialog  value", dialogValue)}
          />
        </DialogContent>
        <DialogActions>
          <Button onClick={handleClose} color="primary">
            Cancel
          </Button>
          <Button onClick={handleClose} color="primary">
            Subscribe
          </Button>
        </DialogActions>
      </Dialog>
    </div>
  );
}
导出默认函数FormDialog(){
const[value,setValue]=React.useState();
const[dialogValue,setDialogValue]=React.useState();
const[open,setOpen]=React.useState(false);
常量handleClickOpen=()=>{
setOpen(真);
};
常量handleClose=()=>{
setOpen(假);
};
常量handleChange=(事件)=>{
设定值({
值:event.target.value,
});
};
const handleDialogValueChange=(事件)=>{
设置对话框值({
dialogValue:event.target.value,
});
};
常量setOriginalTextValue=()=>{
设定值({
value:dialogValue,
});
};
返回(
订阅
请在这里键入文本
取消
订阅
);
}

看起来您正在设置对象,但需要字符串。尝试以下更改:

 const handleChange = (event) => {
    setValue(event.target.value);
  };

const handleDialogValueChange = (event) => {
    setDialogValue(event.target.value);
  };

  const setOriginalTextValue = () => {
    setValue(dialogValue);
  };
useState
这样的设置器期望直接值,因为他们已经“知道”变量名,因为这是他们唯一的责任