【问题标题】:Should you create a custom eventWrapper component for react-big-calendar?你应该为 react-big-calendar 创建一个自定义 eventWrapper 组件吗?
【发布时间】:2019-02-08 15:37:05
【问题描述】:

没有添加eventWrapper 的文档,我看到一些cmets 说它不应该被覆盖。我们应该使用它还是尝试创建自定义 eventWrapper 组件来覆盖这个现有的组件?

对我来说,我不希望.rbc-event-label 也希望在 JS 中动态更改样式。还是我应该只是改变 CSS 中的内容?

【问题讨论】:

    标签: reactjs calendar react-big-calendar


    【解决方案1】:

    您可以使用eventPropGetter 属性为您的事件动态应用其他类和样式。此属性接受一个函数,该函数应返回一个类名和样式的对象以应用于事件(自动添加到 eventWrapper)。

    const eventRenderProps = (event, start, end, isSelected) => {
      let result = {};
      // Code to conditionally add 'className' or 'style' to the result
      return result; // {className?: String, style?: Object}
    }
    
    //
    <MyCalendar eventPropGetter={eventRenderProps} />
    

    请务必注意,在每个显示的事件上都会调用此方法,并且会在每个事件被选择或更改/更新时再次调用。同样重要的是要注意className 是一个字符串,而不是一个对象,因此如果您需要多个类,则需要一个以空格分隔的类名称列表。

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      相关资源
      最近更新 更多