工作中遇到双箭头函数一个bug
const handleRhythmPower = (index: number) => (power: boolean) => {// CODE}// 调用<RhythmsItem// eslint-disable-next-line react/no-array-index-keykey={index}index={index}disabled={disabled}name={name}hour={hour}minute={minute}isValid={power}icon={icons[icon]}brightness={brightness}temperature={temperature}is24Hour={is24HourState}onPower={() => handleRhythmPower(index)}/>//子组件里面<Button size={40} disabled={disabled} onPress={() => onPower && onPower(isValid)}><View style={styles.itemBtn}><IconFontuseART={true}name={isValid ? 'minus' : 'plus'}size={cx(12)}color={themeColor}/></View></Button>
这样子组件使用的是hooks,调用只会进行到onPower={() => handleRhythmPower(index)}这个箭头函数里,不会到handleRhythmPower里面
1 解决办法
A. 我把双箭头函数改为一般的函数就问题解决
B. 我之前用的是class写法,不出现这个问题。用hooks之后出现这个问题
目前解释原理似懂非懂。
