Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

getting error `malformed calls from JS` when using react-native-community/datetimepicker

$
0
0

I am using react-native-community/datetimepicker to select a date. It works fine when I select a date for the first time. But if I again try to open datepicker then it is giving me error.

Below is my code:

const currentDate = Moment();const [show, setShow]: any = useState(false);const [changedDate, setChangedDate] = useState<string | null>(null);const onChange = (event: any, selectedDate: any) => {    setShow(Platform.OS === 'ios');    setDate(currentDate);    var dateInLocal = selectedDate.toLocaleDateString().replace('/', '-');    console.log(dateInLocal);    setChangedDate(dateInLocal);};<View><Text>{changedDate}</Text><TouchableOpacity            onPress={() => {                setShow(true);            }}><Text>open</Text></TouchableOpacity></View>{show && (<DateTimePicker        testID="dateTimePicker"        value={            changedDate ? new Date(changedDate) : currentDate.toDate()        }        mode="date"        is24Hour={true}        display="default"        onChange={onChange}    />)}

Works fine when selecting date for time, below is the error which I am getting when I am trying open datepicker for second time:

enter image description here

I am not able to understand what I am doing wrong..please help


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>