3

I have a boolean in my component's state that I am using to decide whether an element should be in focus.

I use React.createRef() in the constructor and assign the ref to the <input> through its props. Then in render, I use an if statement to check whether the boolean is true, and call inputRef.current.focus() to bring it into focus if it is. The if statement is being triggered, but the element simply isn't being brought into focus.

Any help would be greatly appreciated!

1
  • 3
    A minimal code example would be helpful Commented Jun 16, 2020 at 23:13

1 Answer 1

1

you should use this.inputRef.current.focus()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.