[英]How can I pass a map operation to a component (react datepicker) as a prop?
<DatePicker
selected={startDate}
onChange={handleStartDate}
locale="uk"
dateFormat="dd.MM.yyyy"
placeholderText="Дата початку"
filterDate={isWeekday}
minDate={moment().toDate()}
showMonthPicker
{Object.keys(dateErr).map((key) => {
return <div className={css.error}>{dateErr[key]}</div>;
})}
/>
I need to pass a map operation to a library called "react-datepicker" as a prop, right now the implementation isn't right, need to know how can I pass it我需要将 map 操作作为道具传递给名为“react-datepicker”的库,现在实现不正确,需要知道如何传递它
As @Muhammad B. Aydemir already pointed out and as it is stated in the react-datepicker documentation on the children example, you can only add DatePicker children in between the opening and closing tag whether it is a single component or an array of components.正如@Muhammad B. Aydemir已经指出的那样,正如在子示例的react-datepicker文档中所述,您只能在开始和结束标记之间添加 DatePicker 子项,无论它是单个组件还是组件数组。 Do not forget to add the unique key attribute to each of the children in the passed array or you will get errors.
不要忘记为传递的数组中的每个子元素添加唯一键属性,否则会出错。 In your case it would look something like:
在您的情况下,它看起来像:
<DatePicker
selected={startDate}
onChange={handleStartDate}
locale="uk"
dateFormat="dd.MM.yyyy"
placeholderText="Дата початку"
filterDate={isWeekday}
minDate={moment().toDate()}
showMonthPicker
/>
{Object.keys(dateErr).map((key, index) => {
return <div key={index} className={css.error}>{dateErr[key]}</div>;
})}
</DatePicker>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.