react-native-datepicker icon indicating copy to clipboard operation
react-native-datepicker copied to clipboard

Warning: componentWillReceiveProps is deprecated and will be removed in the next major version. Use static getDerivedStateFromProps instead

Open SnehalAgrawal opened this issue 5 years ago • 15 comments

Hello Admin, Please update for the Warning: componentWillReceiveProps is deprecated and will be removed in the next major version. Use static getDerivedStateFromProps instead. I am using React Native 0.60.

SnehalAgrawal avatar Aug 12 '19 18:08 SnehalAgrawal

+1

cesar3030 avatar Aug 17 '19 03:08 cesar3030

In the datepicker.js file located in node_modules/react-native-datepicker/ I changed the "componentWillRecieveProps" function to the following:

componentDidUpdate(prevProps) { if (prevProps.date !== this.props.date) { this.setState({date: this.getDate(this.props.date)}); } }

This fixed the warning for me and the datepicker works as it should be.

chandreu avatar Aug 20 '19 02:08 chandreu

+1

syntag avatar Sep 06 '19 00:09 syntag

+1

ramonvermeulen avatar Sep 09 '19 13:09 ramonvermeulen

+1

janva255 avatar Oct 07 '19 20:10 janva255

+1

rptoma avatar Oct 08 '19 21:10 rptoma

I guess this guy abandoned the project.

luisAzcuaga avatar Jan 23 '20 02:01 luisAzcuaga

I just found this, hope it helps. A react-native datepicker component https://github.com/react-native-community/react-native-datetimepicker

luisAzcuaga avatar Jan 23 '20 02:01 luisAzcuaga

In the datepicker.js file located in node_modules/react-native-datepicker/ I changed the "componentWillRecieveProps" function to the following:

componentDidUpdate(prevProps) { if (prevProps.date !== this.props.date) { this.setState({date: this.getDate(this.props.date)}); } }

This fixed the warning for me and the datepicker works as it should be.

But what about publishing the app, how we will access the node_modules?

YahiaBadr avatar Apr 02 '20 15:04 YahiaBadr

I made this package https://www.npmjs.com/package/react-native-datepicker-yaya only to solve the warning of the componentWillReceiveProps. Everyone is welcomed to use it instead of this package.

YahiaBadr avatar Apr 02 '20 15:04 YahiaBadr

@YahiaBadr Tried to use your fork, but I believe that the package still relies on DatePickerAndroid & DatePickerIOS, which seem to no longer be a part of @react-native-community/datetimepicker. Any chance you had plans to update it?

mijcabre avatar Apr 07 '20 16:04 mijcabre

@YahiaBadr Tried to use your fork, but I believe that the package still relies on DatePickerAndroid & DatePickerIOS, which seem to no longer be a part of @react-native-community/datetimepicker. Any chance you had plans to update it?

Unfortunately, i tried but it seems it will need some time which i could not have to update this package. However, i made another component based on this package which gives me the same look.

import { View, TextInput, Image } from 'react-native';
import DateTimePickerModal from "react-native-modal-datetime-picker";
import CalenderIcon from "./date_icon.png" //Icon place

const placeHolder = "Select Date";//Placeholder text

class SelectDates extends React.Component {
  state = {
    date: "",
    show: false,
    disabled:false,
    dateValue: placeHolder,
  }
  async componentDidMount() {
    
  }
  open = () =>{
    this.setState({show:true})
    }  
  close = () =>{
    this.setState({show:false})
    }  
render() {
    return (
        <View style={{flexDirection:"row"}}>
            <Image style={{height:35, width:35, marginTop:2.5}} source={CalenderIcon}/>
            <TextInput onTouchStart={this.open} editable={!this.state.show}  value={this.state.dateValue}
                multiline={this.state.dateValue !== placeHolder} textAlignVertical="center"
                style={{borderColor:"#F1F1F1", color:"#F1F1F1", borderWidth:1, height:40, width:"40%", textAlign:"center"}}/>
            <DateTimePickerModal
                // Leave this two as they are
                isVisible={this.state.show}
                date={this.state.dateValue !== placeHolder?new Date(this.state.dateValue):new Date()}
                
                //Change these to satisfy your code
                // mode="datetime"
                // onConfirm={(date)=>this.props.onSelect(date)}
                // onCancel={this.close}
                // minimumDate={new Date()}
                // maximumDate={this.state.maxDate}
            />
        </View>
    );
  }  
}

export default SelectDates;

YahiaBadr avatar Apr 07 '20 17:04 YahiaBadr

@YahiaBadr Tried to use your fork, but I believe that the package still relies on DatePickerAndroid & DatePickerIOS, which seem to no longer be a part of @react-native-community/datetimepicker. Any chance you had plans to update it?

Or if you have time, i could give you access to update it in the repo and then publish it.

YahiaBadr avatar Apr 07 '20 17:04 YahiaBadr

Fix please

GabrielDvt avatar Apr 11 '20 20:04 GabrielDvt

This is still an issue. Has anyone found a solution?

syntag avatar Jul 07 '20 02:07 syntag