[英]How to use react-dates with redux-form
I am working on react-dates
with redux-form
.我正在使用redux-form
处理react-dates
。 Logic is already implemented but when I checked the console for it values it showing nothing.逻辑已经实现,但是当我检查控制台的值时,它什么也没显示。 I've already tried but could not able to resolve this issue.我已经尝试过但无法解决此问题。 Could someone please help me how to resolve this issue.有人可以帮我解决这个问题。 Thanks谢谢
<Field component={DateRanger} type="text" name="date" label="Select Project" />
Date Component日期组件
export class DateRanger extends Component {
constructor(props) {
super(props)
this.state = {
startDate: null,
endDate: null,
focusedInput: null,
}
}
onFocusChange = (value) => {
this.setState({ focused: !this.state.focused })
const { input } = this.props
input.onFocus(value)
}
render() {
const { startDate, endDate, focusedInput } = this.state
const { input } = this.props
return (
<div className="defaultBorderColor">
<DateRangePicker
{...input}
isOutsideRange={(day) => !isInclusivelyBeforeDay(day, moment())}
startDate={startDate}
className="activeDatePicker"
date={input.value}
endDate={endDate}
startDateId="date_input_start"
endDateId="date_input_end"
onDatesChange={({ startDate: dateStart, endDate: dateEnd }) => {
input.onChange(input.value)
this.setState(() => {
return {
startDate: dateStart,
endDate: dateEnd,
}
})
}}
numberOfMonth={1}
focusedInput={focusedInput}
onFocusChange={(input) => this.setState({ focusedInput: input })}
showClearDates
minimumNights={0}
/>
</div>
)
}
}
You are sending for input.onChange(input.value)
the same previous value that redux-form holds.您正在为input.onChange(input.value)
发送与 redux-form 相同的先前值。 so you are not changing the form state actually.所以你实际上并没有改变表格 state 。
onDatesChange={({ startDate: dateStart, endDate: dateEnd }) => {
input.onChange(input.value)
this.setState(() => {
return {
startDate: dateStart,
endDate: dateEnd,
}
})
}}
You need to change it to您需要将其更改为
input.onChange({
startDate: dateStart,
endDate: dateEnd,
})
i would also point that you dont need, IMO, to both hold an internal state and redux state.我还要指出,IMO,您不需要同时持有内部 state 和 redux state。 this should be a controlled input by redux form.这应该是 redux 形式的受控输入。 you get input.value
and input.onChange
你得到input.value
和input.onChange
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.