Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
ReactJS Can't get value of something because not rendered yet, but the function where i get value is called in the rendering

in my React app, I am making a contact form. At the moment I am trying to make it actually send an email, but the thing is that the function where i get the values of an input form (and then send the values in an email), needs to be made before the render of the input form, because the function is called in the render of the input form (in the onSubmit part). But because the elements aren't rendered yet, i can't get the values of them. So unless i made a dumb mistake or something, I'm in some sort of loop.

My code:

import logo from './logo.svg';
import './App.css';
import ContactForm from './contactForm.js'
import React from 'react';
import emailjs from '@emailjs/browser';

function sendEmail() {
  const nameValue = document.getElementById('nameInputId').value;
  const emailValue = document.getElementById('emailInputId').value;
  const subjectValue = document.getElementById('subjectInputId').value;
  const messageValue = document.getElementById('messageInputId').value; 
  const templateParams = {
    from_name: nameValue,
    from_email: emailValue,
    subject: subjectValue,
    message: messageValue
  }
  emailjs.send('service_vaofx8t', 'template_vh7z7yf', templateParams, '8r5pAEVrvJN47utJv');
}

class App extends React.Component {
  render() {
    return (
      <ContactForm submit={sendEmail()} />
    );
  }
};



export default App;

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!