File tree Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -11,15 +11,10 @@ import styles from 'components/TextInput/TextInput.scss';
11
11
import { withForwardedRef } from 'lib/withForwardedRef' ;
12
12
13
13
class TextInput extends React . Component {
14
- componentWillReceiveProps ( props ) {
14
+ componentDidUpdate ( props ) {
15
15
if ( props . multiline !== this . props . multiline ) {
16
16
const node = props . forwardedRef . current ;
17
- // wait a little while for component to re-render
18
- setTimeout ( function ( ) {
19
- node . focus ( ) ;
20
- node . value = '' ;
21
- node . value = props . value ;
22
- } . bind ( this ) , 1 ) ;
17
+ node . focus ( ) ;
23
18
}
24
19
}
25
20
Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ import React from 'react';
2
2
3
3
export function withForwardedRef ( Component ) {
4
4
function render ( props , ref ) {
5
- return < Component { ...props } forwardedRef = { ref } /> ;
5
+ const innerRef = React . useRef ( ) ;
6
+ React . useImperativeHandle ( ref , ( ) => innerRef . current , [ props . multiline ] ) ;
7
+ return < Component { ...props } forwardedRef = { innerRef } /> ;
6
8
}
7
9
8
10
const name = Component . displayName || Component . name ;
You can’t perform that action at this time.
0 commit comments