avatar

ShīnChvën ✨

Effective Accelerationism

Powered by Druid

Update value of ProFormDateRangePicker

Thu Jun 01 2023

If the value of ProFromDateRnagePicker isn't changed when you call form.setFieldValue({dateRange: [Moment, Moment]}). That might be because you passed the same instance of Moment to the ProFormDateRangePicker. You should pass a new instance of Moment to the ProFormDateRangePicker to trigger the value change.

import { ProFormDateRangePicker } from '@ant-design/pro-form';
import moment from 'moment';

const [form] = Form.useForm();

// get the value of ProFormDateRangePicker
const [start, end] = form.getFieldValue('dateRange');

// modify dateRange
start.add(1, 'day');
end.add(1, 'day');

// set new instance of Moment to ProFormDateRangePicker instead of the original
form.setFieldValue('dateRange', [moment(start), moment(end)]);