React Native styling with conditional

后端 未结 3 1381
深忆病人
深忆病人 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 01:55

    There are two ways, by inline or calling a function:

    1)

    const styles = StyleSheet.create({
        green: {
            borderColor: 'green',
        },
        red: {
            borderColor: 'red',
        },
        
    });
    
    
    
    getstyle(val) {
        if (val) {
            return { borderColor: 'red' };
        }
        else {
            return { borderColor: 'green' };
        }
    }
    
    
    

提交回复
热议问题