Javascript 在设置状态以立即被react native上的日历条读取时出现问题
我目前正在使用react native calendar strip,它显示一个水平/线性/每周日历,不管你怎么称呼它,我的想法是单击一个特定的日期并突出显示它,但是这个组件的工作方式将突出显示样式和日期样式分开Javascript 在设置状态以立即被react native上的日历条读取时出现问题,javascript,typescript,react-native,Javascript,Typescript,React Native,我目前正在使用react native calendar strip,它显示一个水平/线性/每周日历,不管你怎么称呼它,我的想法是单击一个特定的日期并突出显示它,但是这个组件的工作方式将突出显示样式和日期样式分开 const [isToday, setToday] = useState(false) <CalendarStrip useIsoWeekday={false} starti
const [isToday, setToday] = useState(false)
<CalendarStrip
useIsoWeekday={false}
startingDate={fecha}
showMonth={false}
calendarHeaderContainerStyle={
styles.calendarHeaderContainerStyle
}
calendarColor={'#FFFFFF'}
style={styles.calendarStripContainer}
daySelectionAnimation={{
type: 'background',
highlightColor: '#F8F8F8',
duration: 300,
}}
onDateSelected={async (date) => {
updateState(date);
DataManager.FechaActual = Moment(date).format('YYYY-MM-DD');
await setFechaActual();
}}
dateNumberStyle={styles.calendarStripMediumText}
dateNameStyle={styles.calendarStripLowText}
highlightDateNumberStyle={[
styles.enabledDate,
{color: isToday ? '#212B42' : '#8E9CB4'},
]}
highlightDateNameStyle={[
styles.enabledDate,
{color: isToday ? '#212B42' : '#8E9CB4'},
]}
disabledDateNameStyle={styles.disabledDate}
disabledDateNumberStyle={styles.disabledDate}
customDatesStyles={customDatesStylesFunc}
disabledDateOpacity={1}
leftSelector={[]}
rightSelector={[]}
iconContainer={{flex: 0.1}}
/>
这是我在onDateSelected中调用的函数
function updateState(date: any) {
var hoy = Moment(horaActual).isSame(Moment(date), 'days');
setToday(hoy);
}
你使用MomentJS做这个有什么原因吗?对
const now=new Date()的简单检查不是吗;date.year===now.year&&date.month===now.month&&date.day===now.day
足够吗?@IcyTv老实说,我不在乎date是否比momentjs更好、更有效,我只是喜欢moment以及你处理格式和比较的方式。你为什么要使用momentjs?对const now=new Date()的简单检查不是吗;date.year===now.year&&date.month===now.month&&date.day===now.day
足够吗?@IcyTv老实说,我不在乎date是否比momentjs更好、更有效,我只是喜欢moment以及处理格式和比较的方式
function updateState(date: any) {
var hoy = Moment(horaActual).isSame(Moment(date), 'days');
setToday(hoy);
}