File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2668,7 +2668,33 @@ You can download the PDF and Epub version of this repository from the latest run
26682668 ReactDOM .render (< App / > , document .getElementById (' app' ))
26692669 ` ` `
26702670
2671+ Also in Functional component (react 16.08 and above)
2672+
2673+ ` ` ` jsx harmony
2674+ import React , {useEffect , useRef } from ' react' ;
2675+
2676+ const App = () => {
2677+ const inputElRef = useRef (null )
2678+
2679+ useEffect (()=> {
2680+ inputElRef .current .focus ()
2681+ }, [])
2682+
2683+ return (
2684+ < div>
2685+ < input
2686+ defaultValue= {' Won\' t focus' }
2687+ / >
2688+ < input
2689+ ref= {inputElRef}
2690+ defaultValue= {' Will focus' }
2691+ / >
2692+ < / div>
2693+ )
2694+ }
26712695
2696+ ReactDOM .render (< App / > , document .getElementById (' app' ))
2697+ ` ` `
26722698 **[⬆ Back to Top](#table-of-contents)**
26732699
26742700108. ### What are the possible ways of updating objects in state?
You can’t perform that action at this time.
0 commit comments