React Native styling with conditional

后端 未结 3 1380
深忆病人
深忆病人 2021-02-01 01:49

I\'m new to react native. I\'m trying to change the styling of the TextInput when there is an error.

How can I make my code not as ugly?



        
3条回答
  •  生来不讨喜
    2021-02-01 02:03

    Update your code as following:

    
    

    Then outside your class component, write:

    getTextStyle(touched, invalid) {
     if(touched && invalid) {
      return {
        height: 40, backgroundColor: 'white', borderRadius: 5, padding: 10, borderWidth: 2, borderColor: 'red'
      }
     } else {
       return {
          height: 40, backgroundColor: 'white', borderRadius: 5, padding: 10
       }
     }
    }
    

提交回复
热议问题