每天显示2个日历(Georgian和Hijri)

时间:2019-05-22 13:35:01

标签: react-day-picker

如何使用react-day-picker每天显示格鲁吉亚和回历日?目标就是这样

enter image description here

1 个答案:

答案 0 :(得分:0)

实际上,解决方案非常简单,我只是很着急。 如果您使用的是react-day-picker,则可以利用renderDay属性来计算回历日期并自定义每天的单元格。

这是一个可行的例子

import React from "react";
import ReactDOM from "react-dom";
import DayPicker from "react-day-picker";
import hijriDate from "hijrah-date";

import "react-day-picker/lib/style.css";
import "./styles.css";

const renderDay = day => {
  const date = day.getDate();
  const hijDate = new hijriDate(day);
  const d = hijDate.getDate();

  return (
    <div>
      <span>{date}</span>
      <br />
      <small>{d}</small>
    </div>
  );
};
function App() {
  return (
    <div className="App">
      <DayPicker renderDay={renderDay} />
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);