两个功能在一个功能内一个作为道具,一个作为功能



我正在为日历创建一个通用组件。我需要在一个函数中调用两个函数,比如:-

onDateChange = {()=>{ props.onDateChange,setShowCal()}}

因此CCD_ 1一旦选择就可以关闭日历,并且CCD_。

但只有CCD_ 3在工作而CCD_。

通用组件的完整代码:-

export const PrimaryCalendar = (props)=>{
const [showCal, setShowCal] = React.useState(false);
const mindate = new Date();
const showCalendar = ()=>{
setShowCal(!showCal)
}
return(
<View>
{(showCal) ? 
<View style={styles.container}>
<CalendarPicker
selectedDayColor="#079B2B"
minDate = {mindate}
startFromMonday={true}
allowRangeSelection={true}
todayBackgroundColor="#79AE08"
previousTitle="Previous"
nextTitle="Next"
onDateChange = {()=>{ props.onDateChange,setShowCal()}}
/>
</View>
:
<View>
<TouchableOpacity style={styles.calendarInputContainer} onPress={()=>showCalendar()}>
<Text style={{color:'white', fontSize:25}}>{props.title}</Text>
<Icon name="calendar" size={30} color={'white'}/>
</TouchableOpacity>
</View>
}
</View>
)

}

我该如何实现它?谢谢

export const PrimaryCalendar = (props)=>{
const [showCal, setShowCal] = React.useState(false);
const mindate = new Date();
const showCalendar = ()=>{
setShowCal(!showCal)
}
const handleOnDateChange = () =>{
props.onDateChange()
setShowCal()
}
return(
<View>
{(showCal) ? 
<View style={styles.container}>
<CalendarPicker
selectedDayColor="#079B2B"
minDate = {mindate}
startFromMonday={true}
allowRangeSelection={true}
todayBackgroundColor="#79AE08"
previousTitle="Previous"
nextTitle="Next"
onDateChange = { handleOnDateChange }
/>
</View>
:
<View>
<TouchableOpacity style={styles.calendarInputContainer} onPress={()=>showCalendar()}>
<Text style={{color:'white', fontSize:25}}>{props.title}</Text>
<Icon name="calendar" size={30} color={'white'}/>
</TouchableOpacity>
</View>
}
</View>
)

让您的onChange回调执行一个名为handleTextAreaChange的函数,然后该函数将执行props.onDateChange()setShowCal()

你的错误是onDateChange = {()=>{ props.onDateChange,setShowCal()}}

当声明setShowCal()0时,花括号内的内容是一个代码块,这意味着用逗号分隔函数调用是错误的。

以下是如何完成的示例

onChange={ () => {
functionCall1()
functionCall2()
} }

最新更新