Answer the question
In order to leave comments, you need to log in
Why do you have to use async in React to get what you want?
Maybe the method is crooked, but it works.
I know that this.state works in react asynchronously, as far as I understand. But here I am using Mobx and I don't have this.state anywhere.
const textInput = useRef(null);
const editTodo = async () => {
await onEditTodo(id);
console.log("textInput.current", textInput.current);
};
// код
return (
<input ref={textInput} />
);
Answer the question
In order to leave comments, you need to log in
because everything is re-rendered, and the focus is lost
, you can solve it with a similar hack, but in general I’ll listen if there are other options
setTimeout(() => {
textInput.current.focus()
}, 0) // сработает в следующем цикле event loop-a после рендера
I would take it by className, but right there I need to put the focus in the Todo that I clicked on
document.querySelector('input[data-id="456"]')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question