Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onchange Doesn't work #943

Closed
Alisonais opened this issue Nov 15, 2024 · 2 comments
Closed

Onchange Doesn't work #943

Alisonais opened this issue Nov 15, 2024 · 2 comments

Comments

@Alisonais
Copy link

Question

@trikecarlan
Copy link

yeah..anyone encountered this and how you solved this.
The onchange keep on setting the default state to original. when the calendar ui is displayed and select date, it goes back to the original selected Date.

import React, { useState } from 'react';
import { View, Button, Platform, Text } from 'react-native';
import DateTimePicker, { DateTimePickerEvent } from '@react-native-community/datetimepicker';
import { Fontisto } from '@expo/vector-icons';

type DatePickerInputProps = {
date: Date;
setDate: React.Dispatch<React.SetStateAction>
};

const DatePickerInput: React.FC = ({
date = new Date(),
setDate,
}) => {
const [show, setShow] = useState(false);

const onChange = (event: DateTimePickerEvent, selectedDate?: Date) => {
    console.log(selectedDate)
    if (event.type === 'set' && selectedDate) {
        setDate(selectedDate);
    }
    setShow(false)
};

return (
    <View>
        <Fontisto onPress={() => setShow(true)} name="date" size={24} color="orange" />
        {show && (
            <DateTimePicker
                value={date}
                mode="date"
                display="default"
                onChange={onChange}
            />
        )}
    </View>
);

};

export default DatePickerInput;

Copy link

👋 @Alisonais, sorry you're having an issue. This issue is being closed because it does not provide all information required by the issue template. As the issue template explains, we require that you provide a runnable example that reproduces your issue and your environment information. This means you need to provide a code snippet that we can copy-paste into an empty project and see the error ourselves, or provide a git repository with the issue.
The reason is that maintainers do not have time to try reproduce bugs themselves. Please try to minimize the superfluous code and focus only on reproducing the bug.
Please create a new issue with this and we'll be happy to review it!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants