【发布时间】:2021-12-31 17:43:23
【问题描述】:
我正在使用 react-native-calendars。
我有一个<Calendar/> 组件。
我已经阅读了数十次文档,但找不到比 current 属性更好的更改月份的属性,它初始化了日历的视图。例如,如果我设置current={"2014-01-01"},我会看到 2014 年 1 月 1 日的日历。问题是我无法重新渲染这个道具。
我也尝试使用key 道具,但它不会更改日期。 Ref 也不是一个选项,我有自定义 <CalendarHeader/>
package.json
"react": "17.0.2",
"react-native": "0.66.4",
"react-native-calendars": "1.1274.0"
Calendar.tsx
const CalendarScreen = () => {
const [current, setCurrent] = useState('2020-01-01');
return (
<Calendar
current={current}
customHeader={CalendarHeaderHandler}
style={styles.calendar}
/>
<TouchableOpacity onPress={() => setCurrent('2021-01-01')}>
<Text>2021</Text>
</TouchableOpacity>
)};
【问题讨论】:
标签: react-native react-native-calendars