|
1 | | -import React, {PureComponent} from 'react'; |
| 1 | +import React, {useRef, useEffect} from 'react'; |
2 | 2 | import {Animated} from 'react-native'; |
3 | 3 | import styles from '../../../styles/styles'; |
4 | 4 | import {propTypes, defaultProps} from './TextInputLabelPropTypes'; |
5 | 5 | import CONST from '../../../CONST'; |
6 | 6 |
|
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) { |
10 | 12 | return; |
11 | 13 | } |
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 | + }, []); |
14 | 17 |
|
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 | + ); |
27 | 28 | } |
28 | 29 |
|
| 30 | +TextInputLabel.displayName = 'TextInputLabel'; |
29 | 31 | TextInputLabel.propTypes = propTypes; |
30 | 32 | TextInputLabel.defaultProps = defaultProps; |
31 | 33 |
|
32 | | -export default TextInputLabel; |
| 34 | +export default React.memo(TextInputLabel); |
0 commit comments