工作中遇到双箭头函数一个bug

    1. const handleRhythmPower = (index: number) => (power: boolean) => {
    2. // CODE
    3. }
    4. // 调用
    5. <RhythmsItem
    6. // eslint-disable-next-line react/no-array-index-key
    7. key={index}
    8. index={index}
    9. disabled={disabled}
    10. name={name}
    11. hour={hour}
    12. minute={minute}
    13. isValid={power}
    14. icon={icons[icon]}
    15. brightness={brightness}
    16. temperature={temperature}
    17. is24Hour={is24HourState}
    18. onPower={() => handleRhythmPower(index)}
    19. />
    20. //子组件里面
    21. <Button size={40} disabled={disabled} onPress={() => onPower && onPower(isValid)}>
    22. <View style={styles.itemBtn}>
    23. <IconFont
    24. useART={true}
    25. name={isValid ? 'minus' : 'plus'}
    26. size={cx(12)}
    27. color={themeColor}
    28. />
    29. </View>
    30. </Button>

    这样子组件使用的是hooks,调用只会进行到onPower={() => handleRhythmPower(index)}这个箭头函数里,不会到handleRhythmPower里面

    1 解决办法
    A. 我把双箭头函数改为一般的函数就问题解决

    B. 我之前用的是class写法,不出现这个问题。用hooks之后出现这个问题

    目前解释原理似懂非懂。