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

409
Views
(Campo de texto MUI) TypeError no capturado: no se pueden leer las propiedades de undefined (leyendo 'focus')

Actualmente estoy usando el enlace useRef en el campo de texto Material Ui, y seguí recibiendo el error Uncaught TypeError: Cannot read properties of undefined (reading 'focus') , y no tengo idea de cómo resolverlo. Mi código se ve así:

 const LoginTextField = styled(TextField)({ '& .MuiInput-underline:after': { borderBottomColor: 'white', }, '& .MuiOutlinedInput-root': { '& fieldset': { borderColor: '#263238', }, input: { color: 'white' }, backgroundColor: '#263238' } }); export default function test() { const userRef = useRef(); const [loginEmail, setLoginEmail] = useState(''); useEffect(() => { userRef.current.focus(); }, []) <LoginTextField label='Email' variant='outlined' onChange={(e) => setLoginEmail(e.target.value)} inputRef={userRef} InputLabelProps={{ style: { color: 'white' } }} /> }

¿Alguien tiene una idea de lo que está mal con mi código? Muchas gracias.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

oye, creo que sería mejor si primero inicializas el valor en userRef().

Entonces, piense en useRef como useState, donde el estado se guarda en el siguiente renderizado, así que creo que también debe decidir qué useRef desea hacer, como actualizar el correo electrónico o la contraseña.

Por ejemplo: useRef('') o null o lo que quiera que sea el estado/valor inicial/predeterminado en su caso.

Entonces tal vez podrías crear una función

 const myFunction = () => { // update the state or what you actually want to implement }

Luego ejecutaría myFunction dentro de useEffect.

Espero que eso ayude.

Compruebe también esto: https://dmitripavlutin.com/react-useref-guide/

about 4 years ago · Juan Pablo Isaza Report
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!