React: set focus on componentDidMount, how to do it with hooks? : <p>In React, with classes I can set the focus to an input when the component loads, something like this:</p>

<pre><code>class Foo extends React.Component {
    txt1 = null;

    componentDidMount() {
        this.txt1.focus();
    }

    render() {
        return (
            &lt;input type="text"
                ref={e =&gt; this.txt1 = e}/&gt;
        );
    }
}
</code></pre>

<p>I'm trying to rewrite this component using the new <a href="https://reactjs.org/docs/hooks-intro.html" rel="noreferrer">hooks proposal</a>.</p>

<p>I suppose I should use <a href="https://reactjs.org/docs/hooks-effect.html" rel="noreferrer"><code>useEffect</code></a> instead of <code>componentDidMount</code>, but how can I rewrite the focus logic?</p>
