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

138
Views
How do i access a ref.current.value outside of the set scope

Here i have some React code ->

React refs

 const noteTitleRef = React.createRef();
 const noteBodyRef = React.createRef();

Button component

           <LoadingButton
                  color="secondary"
                  onClick={() => {
                    setLoading(true);
                      addNote(noteTitleRef.current.value, noteBodyRef.current.value);
                      setLoading(false);
                  }}
                  loading={loading}
                  loadingPosition="start"
                  startIcon={<SaveIcon />}
                  variant="contained"
                >
                  Save
                </LoadingButton>

If i change Button component to

           <LoadingButton
                  color="secondary"
                  onClick={() => {
                    setLoading(true);
                    setTimeout(() => {
                      addNote(noteTitleRef.current.value, noteBodyRef.current.value);
                      setLoading(false);
                    }, 1000);
                  }}
                  loading={loading}
                  loadingPosition="start"
                  startIcon={<SaveIcon />}
                  variant="contained"
                >
                  Save
                </LoadingButton>

Then the noteTitleRef.current.value & noteBodyRef.current.value becomes null and doesn't work.

How do i get around this? I would like to set a delay to my onClick, and after 1 second then i want the addNote() function to fire passing the noteTitleRef.current.value, noteBodyRef.current.value as parameters.

I appreciate all feedback!

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!