Skip to content

Commit 3272a3c

Browse files
authored
Merge pull request sudheerj#169 from Nelsonfrank/Nelsonfrank-patch-1
Add functional component solution to question 107
2 parents 28a6660 + cfcb8be commit 3272a3c

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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
26742700
108. ### What are the possible ways of updating objects in state?

0 commit comments

Comments
 (0)