Fix re-render selectedValue
Hoshiiii2602 opened this issue ยท 0 comments
Hoshiiii2602 commented
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch react-native-wheel-pick@1.2.2
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/react-native-wheel-pick/src/picker.js b/node_modules/react-native-wheel-pick/src/picker.js
index f86dd33..9de2733 100644
--- a/node_modules/react-native-wheel-pick/src/picker.js
+++ b/node_modules/react-native-wheel-pick/src/picker.js
@@ -46,11 +46,11 @@ export default class Picker extends Component {
};
validateDeprecateProps = (oldProp = 'curtain', newProp = '') => {
- if(this.props){
- if(typeof this.props[oldProp] !== 'undefined'){
+ if (this.props) {
+ if (typeof this.props[oldProp] !== 'undefined') {
this.props[oldProp] = undefined;
- if(newProp === ''){
+ if (newProp === '') {
console.warn(`react-native-wheel-pick : "${oldProp}" Prop was deprecated. Please remove it for improve native performance.`)
} else {
console.warn(`react-native-wheel-pick : "${oldProp}" Prop was deprecated. Please use "${newProp}" instead.`)
@@ -59,10 +59,16 @@ export default class Picker extends Component {
}
}
+ componentDidUpdate(prevProps) {
+ if (prevProps.selectedValue !== this.props.selectedValue) {
+ this.setState({ selectedValue: this.props.selectedValue });
+ }
+ }
+
render() {
const { pickerData, style, ...props } = this.props;
- if(Platform.OS === 'android'){
+ if (Platform.OS === 'android') {
//checkDeprecatedProp
this.validateDeprecateProps('atmospheric');
this.validateDeprecateProps('curved');
This issue body was partially generated by patch-package.