DEV Community

Managing Focus in React

Chris Westbrook on August 04, 2019

There are times when you may wish to set focus to a specific element in your react component, such as when the component first mounts, or perhaps a...
Collapse
 
dance2die profile image
Sung M. Kim

Thank you for the easy-to-digest post, Chris.

May I ask why you've used createRef over useRef? I've never done focus management thus not sure if createRef is preferred.

Collapse
 
westbrookc16 profile image
Chris Westbrook

No reason, I think I saw react.createRef somewhere and forgot about useRef. I have updated the post since useRef is more consistent. Thanks so much for the feedback.

Collapse
 
nishchit6 profile image
Nishchith Rao

I tried with useRef..it does not seem to work...The current value is still null..Its not updated..Any solutions??
Thank you!!

Collapse
 
stomperhk profile image
Rafael

I don't know why, but refName.current.focus() just doesn't give me any visual result.

Collapse
 
sshakirbekovv profile image
Yerkebulan

hi

Collapse
 
sshakirbekovv profile image
Yerkebulan

test

Collapse
 
sshakirbekovv profile image
Yerkebulan

ddd

Collapse
 
sshakirbekovv profile image
Yerkebulan

php

Collapse
 
sshakirbekovv profile image
Yerkebulan

test

Collapse
 
sshakirbekovv profile image
Yerkebulan

PHP

Collapse
 
sshakirbekovv profile image
Yerkebulan

hh

Collapse
 
sshakirbekovv profile image
Yerkebulan

gg

Collapse
 
sshakirbekovv profile image
Yerkebulan

///