Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda