Skip to content

Commit be9c400

Browse files
authored
Merge pull request #23547 from kosmydel/@swm/migration/text-input-label
Migrate TextInputLabel/index.js to a functional component
2 parents 5f0a741 + 26b3b10 commit be9c400

File tree

1 file changed

+21
-19
lines changed
  • src/components/TextInput/TextInputLabel

1 file changed

+21
-19
lines changed
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
import React, {PureComponent} from 'react';
1+
import React, {useRef, useEffect} from 'react';
22
import {Animated} from 'react-native';
33
import styles from '../../../styles/styles';
44
import {propTypes, defaultProps} from './TextInputLabelPropTypes';
55
import CONST from '../../../CONST';
66

7-
class TextInputLabel extends PureComponent {
8-
componentDidMount() {
9-
if (!this.props.for) {
7+
function TextInputLabel({for: inputId, label, labelTranslateY, labelScale}) {
8+
const labelRef = useRef(null);
9+
10+
useEffect(() => {
11+
if (!inputId || !labelRef.current) {
1012
return;
1113
}
12-
this.label.setAttribute('for', this.props.for);
13-
}
14+
labelRef.current.setAttribute('for', inputId);
15+
// eslint-disable-next-line react-hooks/exhaustive-deps
16+
}, []);
1417

15-
render() {
16-
return (
17-
<Animated.Text
18-
ref={(el) => (this.label = el)}
19-
pointerEvents="none"
20-
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
21-
style={[styles.textInputLabel, styles.textInputLabelDesktop, styles.textInputLabelTransformation(this.props.labelTranslateY, 0, this.props.labelScale)]}
22-
>
23-
{this.props.label}
24-
</Animated.Text>
25-
);
26-
}
18+
return (
19+
<Animated.Text
20+
ref={labelRef}
21+
pointerEvents="none"
22+
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
23+
style={[styles.textInputLabel, styles.textInputLabelDesktop, styles.textInputLabelTransformation(labelTranslateY, 0, labelScale)]}
24+
>
25+
{label}
26+
</Animated.Text>
27+
);
2728
}
2829

30+
TextInputLabel.displayName = 'TextInputLabel';
2931
TextInputLabel.propTypes = propTypes;
3032
TextInputLabel.defaultProps = defaultProps;
3133

32-
export default TextInputLabel;
34+
export default React.memo(TextInputLabel);

0 commit comments

Comments
 (0)