Displaying a value in a React component using material-ui's TextField

Can anyone help me with printing the email a user enters into the textfield within the Dialog when a button is clicked? I have been struggling to achieve this due to my function's structure. Any guidance would be greatly appreciated.

export default function ConsultantsHeader (props) {
  
  
  return (
            <div>
      
            <Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
              <DialogTitle id="dialog-title">Invite Consultant</DialogTitle>
              <DialogContent>
                <DialogContentText>
                  To invite a new X, please enter their email below:
                </DialogContentText>
                <TextField
                  autoFocus
                  margin="dense"
                  id="email"
                  label="Email Address"
                  type="email"
                  fullWidth
                  color="secondary"
                  variant="outlined"
                />
              </DialogContent>
              <DialogActions>
                <Button 
                color="inherit"
                size="small"
                onClick={handleClose} >
                  Cancel
                </Button>
                <Button 
                  onClick={inviteConsultant}
                  variant="contained"
                  color="secondary"
                  size="small">
                Send Invite
                </Button>
              </DialogActions>
            </Dialog>
    </div>
  );
}

Answer №1

This is how I accomplished it:

    const [email, setEmail] = useState('');

  const submit = (event) => {
    const myEmail = email;

    console.log(email);

    event.preventDefault();
  };

Additionally,

<TextField
              autoFocus
              margin="dense"
              id="email"
              label="Email Address"
              type="email"
              fullWidth
              color="secondary"
              variant="outlined"
              value={email}
              onChange={(event) => {
                setEmail(event.target.value);
              }}
            />
          </DialogContent>
          <DialogActions>
            <Button 
            color="inherit"
            size="small"
            onClick={handleClose} >
              Cancel
            </Button>
            <Button 
              onClick={inviteConsultant}
              variant="contained"
              color="secondary"
              size="small"
              onClick={(event) => submit(event)}>
              Send Invite
            </Button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to positioning an image absolutely within a div

I am struggling to position a small close image within a div without success. The goal is for the image to always appear on the left side of the div, regardless of the content. The content consists of a text label with a maximum length of 8 characters. Iss ...

How to activate a window that's been minimized in Chrome

I am experiencing an issue with a button that is supposed to open a new window as a popup below the parent page. It works correctly in IE and Firefox, but in Chrome, the popup appears on top of the parent window. Can someone please provide a solution? Fo ...

Align dropdown navigation menu/sorting dropdown in the same position as the button

Exploring the world of dropdown menus in CSS has led me to encounter some challenges. I am striving to ensure that the dropdown boxes appear on the same line as the button that triggers them. Below is the CSS code I have been working with: /* global style ...

The selector often yields varying results when used in a traditional browser versus when it is utilized with Selenium

When using Firefox in the console, I can enter: $("a:contains('tekst')") and it will display: object { length: 1, ... } However, when attempting the same in firefox opened by behat with sellenium, I receive the error message: SyntaxError: An ...

What steps can be taken to address the JavaScript error that states: Error : TypeError: $("j2t-temp-div").down(".j2t_ajax_message") is not defined?

If you want to see the issue in action, please visit this link. To replicate this error, choose a "Color" and "Size", then click "Add to Cart". While the "loading..." dialog box is still visible, click on the shade to close it. Quickly click on any other ...

"Aligning two images side by side in a horizontal

[enter image description here][1]I am trying to place two images on my website, but I am struggling to vertically align them properly. I have attempted using line-height and vertical alignment, however, I cannot seem to pinpoint the issue or identify any m ...

The Carousel is covering up my Mega-Menu and it is not visible on top

I'm facing an issue where my mega menu is hidden behind the carousel, and I need it to show on top. You can see how it looks before adding the carousel and after adding the carousel from Bootstrap. Here are the links to the Mega Menu CSS and Mega menu ...

challenges faced when sending requests through nginx and express router

I've been working on setting up two Node/Express sites behind Nginx. Despite trying various solutions from forums, I'm only getting partial success. My goal is to have: - one domain with two Node/Express apps 1.) node.dev/site3 2.) node.dev/site ...

The debounce function seems to be malfunctioning as I attempt to refine search results by typing in the input field

Currently, I am attempting to implement a filter for my search results using debounce lodash. Although the filtering functionality is working, the debounce feature seems to be malfunctioning. Whenever I input text into the search bar, an API call is trigge ...

Obtain SVG icons seamlessly in Next.js

My goal was to dynamically retrieve SVG icons, and I discovered a method to achieve this. However, it seems like I have made some errors along the way. Can you point out where I am going wrong? Icon.js import React from "react"; import { ReactCo ...

How can one change the data type specified in an interface in TypeScript?

I am currently diving into TypeScript and looking to integrate it into my React Native application. Imagine having a component structured like this: interface Props { name: string; onChangeText: (args: { name: string; value: string }) => void; s ...

Tips for Maintaining User Data Across Pages in React using React-Router-Dom and Context

I've been tackling the login functionality of a client-side application. Utilizing React alongside TypeScript, I've incorporated react-router-dom and Context to manage the user's data when they log in. However, upon refreshing the page, the ...

What is the best method to transfer information from a What You See Is What You Get editor to a database using Vue.js?

I have recently started using the Vue2Editor in order to streamline my process of sending text and image data to my Firebase database. However, I am encountering an issue where the entered data is not being added successfully. Previously, with traditional ...

The issue of conflicting dependencies arises between [email protected] and @apollo/[email protected]

I am encountering an issue with @apollo while working on my react project, and I keep receiving the following error: npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @apollo/<a href="/cdn-cgi/l/email-protect ...

NuxtJS using Babel 7: the spread operator persists in compiled files

Struggling to get my NuxtJS app functioning properly on IE11. Despite multiple attempts to configure Babel for compatibility, spread operators are still present in the built pages files, suggesting that Nuxt code is not being transformed correctly. Below ...

I need to condense my layout from three columns to just two columns in HTML

The html code for "Date Accessed" is meant to be in one column as a header, while the actual dates should be in another column, but somehow they are all appearing in a single column. I am having trouble figuring out why. <!DOCTYPE html> {% load stati ...

How to identify generic return type in TypeScript

My goal is to develop a core dialog class that can automatically resolve dialog types and return values based on the input provided. I have made progress in implementing this functionality, but I am facing challenges with handling the return values. Each ...

Error encountered while attempting to update using PostgreSQL in Sequelize Database

I have created 5 endpoints with 4 implemented methods. The GET, POST, and DELETE methods are all functioning correctly. However, I am facing an issue with the PUT method. When attempting to update the columns "first_name" and "last_name," I encounter the f ...

Is it necessary to use "require('module/component')" if component.js is not located in the root of the module?

I'm currently in the process of developing a npm package for a few React components. These components will be utilized in various projects, so I prefer to keep them separate from each project. My goal is to be able to import require('comps/a-com ...

Using jQuery, how can I add value to every input when the option is changed?

I need help changing the values of all input:text elements based on selections from a select menu. Specifically, I want to change only the matched td.class values from the data-pset attribute inside the <select>. As a beginner in jQuery, I can only ...