简体   繁体   English

如何将 map 操作作为道具传递给组件(反应日期选择器)?

[英]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.

相关问题 如何将组件作为道具传递给 React 中的另一个组件? - How can I pass a component as a prop into another component in React? 如何将React组件作为prop传递 - How to pass a React component as a prop 在 REACT.js 中,如何将状态从子组件传递到父组件作为道具 - In REACT.js how can I pass a state from child component up to Parent component as a prop React:如何将“未定义”变量作为道具传递给组件? - React: How can you pass a “not defined” variable as a prop to a component? 如何在 React 中将 const 变量作为道具传递给组件? - How do I pass a const variable to a component as a prop in React? 如何在 React 和 Typescript 中将组件作为道具传递? - How do I pass a component as a prop in React and Typescript? 如何将 Prop 传递给导航屏幕组件 - React Native - How do I pass a Prop to a Navigation Screen Component - React Native React-如何通过长时间运行的操作将正确的prop传递给子组件 - React - how to pass the correct prop to a child component from a long running operation React:如何从组件传递宽度作为支撑 - React: How to pass width as a prop from the component 如何将 React Router 位置道具传递给组件? - How to pass the React Router location prop to a component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM