score:1

Accepted answer

yes you need to save value in state. and when user click on subscribe fetch that value from state. here is updated code:

import react from "react";
import button from "@material-ui/core/button";
import textfield from "@material-ui/core/textfield";
import dialog from "@material-ui/core/dialog";
import dialogactions from "@material-ui/core/dialogactions";
import dialogcontent from "@material-ui/core/dialogcontent";
import dialogcontenttext from "@material-ui/core/dialogcontenttext";
import dialogtitle from "@material-ui/core/dialogtitle";
import form from "semantic-ui-react";

export default function formdialog() {
  const [open, setopen] = react.usestate(false);
  const [value, setvalue] = react.usestate("hello");

  const handleclickopen = () => {
    setopen(true);
  };

  const handleclose = () => {
    setopen(false);
  };

  return (
    <div>
      <button variant="outlined" color="primary" onclick={handleclickopen}>
        open form dialog
      </button>
      <dialog
        open={open}
        onclose={handleclose}
        aria-labelledby="form-dialog-title"
      >
        <dialogtitle id="form-dialog-title">subscribe</dialogtitle>
        <dialogcontent>
          <dialogcontenttext>
            to subscribe to this website, please enter your email address here.
            we will send updates occasionally.
          </dialogcontenttext>
          <textfield
            autofocus
            margin="dense"
            id="name"
            label="application name"
            type="text"
            value={value}
            onchange={(e) => setvalue(e.target.value)}
            fullwidth
          />
        </dialogcontent>
        <dialogactions>
          <button onclick={handleclose} color="primary">
            cancel
          </button>
          <button onclick={handleclose} color="primary">
            subscribe
          </button>
        </dialogactions>
      </dialog>
    </div>
  );
}


here is the demo: https://codesandbox.io/s/material-demo-forked-ln0xe?file=/demo.js:0-1824


Related Query

More Query from same tag