-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
add an example of a controlled date range picker #14
Comments
@SSmJaE , hi, thanks for the issue. const [selectedDates, onDatesChange] = useState<Date[]>([]);
const dpState = useDatePickerState({
selectedDates,
onDatesChange,
dates: { toggle: true, mode: 'multiple' },
}); You don't need to create a local state and then call onChange export function DateRangePicker({
value,
onChange,
}: {
value: Date[];
onChange: (value: Date[]) => void;
}) {
const {
data: { weekDays, calendars },
propGetters: { dayButton, previousMonthButton, nextMonthButton },
} = useDatePicker({
dates: {
mode: "range",
},
selectedDates: value,
onDatesChange: onChange,
});
return (COMPONENT GOES HERE);
} Everything else in your code is redundant! 😉 |
@Feshchenko thanks for quick response actually, i have tried what you mentioned earlier so if I log like this onDatesChange : (value) => {
console.log({
valueInPicker: value,
});
} it will output {
valueInPicker : [ Date() ] // not [ Date(), Date() ]
} what i want is, the prop |
@SSmJaE yes, you are right. const [selectedDates, setDates] = useState<Date[]>([]);
const onChange = () => {
console.log('Send me to the BE');
}
const onDateChange = (dates: Date[]) => {
setDates(dates);
if(dates.length === 2) onChange(dates);
} We have the Discord for live help. I'm trying to answer and help as soon as I can :) |
great repo 👍
i have found #4
but this doesn't provide a complete example
so with some struggle, i finally got this
maybe we could add this example to the readme? for someone like controlled style component like me
The text was updated successfully, but these errors were encountered: