How can I get real elment by node id? react-native

前端 未结 7 1555
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 06:05

  CLOSE


_onPress(e) {
         


        
7条回答
  •  天命终不由人
    2020-12-30 06:59

    The concern is about performance so I solve it with this approach

    just create a wrapper around TouchableOpacity or any clickable view

    import { TouchableOpacity } from "react-native"
    
    export const TouchableOpacityOnPressOptimized = ({ children, onPress, index }) => {
      return (
         onPress(index)}>
          {children}
        
      )
    }
    
    const touchMe = (index) => {
        switch(index) {
           case 1: alert('index is' + index)
           case 2: alert('index is' + index)
        }
    }
    
     touch me 1 
    
     touch me 2 
    
     touch me 3 
    

    this way your touchable component not re-render

提交回复
热议问题