Android: DateTimePicker keeps resetting to default value
See original GitHub issueMy DateTimePicker keeps resetting to the default value while open.
Code:
const CustomDateTimePicker = React.memo((onChange) => {
console.log('Rerender CustomDateTimePicker');
const [date, setDate] = useState(new Date('1985/01/01'));
const [show, setShow] = useState(Platform.OS === 'ios');
const onDateChange = useCallback((event, date) => {
setShow(Platform.OS === 'ios');
setDate(date);
onChange(date);
}, []);
useEffect(() => {
console.log('Date changed');
}, [date]);
return (
<View style={{ flexDirection: 'row' }}>
{Platform.OS === 'android' &&
<TouchableOpacity
onPress={() => setShow(true)}
style={{
flex: 1,
marginVertical: 10,
padding: 10,
}}
>
<Text style={{ fontSize: 16 }}>{date && date.toLocaleDateString()}</Text>
</TouchableOpacity>
}
{show &&
<DateTimePicker
testID="dateTimePicker"
textColor={'#ffffff'}
value={date}
mode={'date'}
display='default'
onChange={onDateChange}
/>
}
</View>
)
});
export default CustomDateTimePicker;
When the dialog is open and I select a date, the component will undo my change and go back to the default value after a second or two.
I don’t the console prints while this is happening.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:18
- Comments:17 (2 by maintainers)
Top Results From Across the Web
Datepicker returning to initial value - react native
I'm using react-native-date-picker component to pick date and time values in my app. In Android it's working fine.
Read more >My fields keep resetting to the default values in power apps
Solved: Hi All In power apps I have a Edit form that users capture case related information they go and select date when...
Read more >DevicePolicyManager
In order to protect any sensitive data that remains on the device, it is advised that the device owner factory resets the device...
Read more >react-native-community/datetimepicker
Defines the type of the picker. List of possible values: "date" (default for iOS and Android and Windows ); "time" ...
Read more >Element: <oj-input-date>
When the reset method is called, deferred validation is run after all ... Default values for the datePicker sub-properties can also be ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had a similar issue. I think the problem comes from the re-rendering of the calendar component. Try wrapping your parent component inside useMemo hook and render the component only if show calendar state changes. It worked for me 😃
🎉 This issue has been resolved in version 3.0.9 🎉
The release is available on:
Your semantic-release bot 📦🚀