I'm trying to edit the profile data of the user(which has fullName, gender, birthdate) By far when I edit the birthdate and the name, the profile data is edited. But when I change the name only, and save it it shows this error: TypeError: value.getTime is not a function. (In 'value.getTime()', 'value.getTime' is undefined)
const [date, setDate] = useState(new Date());
const onChangeDate = (event, selectedDate) => {
const currentDate = selectedDate || date;
setShow(Platform.OS === 'ios');
setDate(currentDate);
let tempDate = new Date(currentDate);
let sDate = tempDate.getDate() + '/' + (tempDate.getMonth() + 1) + '/' + tempDate.getFullYear();
setIsValidDate(true);
setDateText(sDate);
};
const getUserData = () => {
axios
.get(`url/${phone}`)
.then((response) => {
setDate(response.data.data[0].birthdate);
})
.catch((error) => {
console.log('error getting data',error);
});
};
...
<View style={{ width: '100%', borderRadius: 8 }}>
{show && (
<DateTimePicker
testID="dateTimePicker"
value={date}
mode={mode}
minimumDate={new Date(1950, 1, 1)}
maximumDate={moment().subtract(16, 'years').format('YYYY-MM-DDTHH:mm:ss.ssSZ')}
is24Hour={true}
display={'default'}
onChange={onChangeDate}
style={styles.datePicker}
/>
)}
</View>
How can I solve this error?
You must parse axios response to Date because birthDate in axios response is string. Error message is correct that string doesn't have to getTime method.