【发布时间】:2021-12-10 17:10:10
【问题描述】:
有没有办法在StyleSheet 中使用三元运算符?
目前,我的TextInput 看起来是这样的:
.tsx
<TextInput
defaultValue={selectedEvent ? selectedEvent.title : ""}
style={[
styles.textInput,
{ color: colorScheme === "dark" ? "#ffffff" : "#000000" },
]}
onChangeText={inputChangeHandler}
/>
样式表
const styles = StyleSheet.create({
textInput: {
borderBottomColor: "#ccc",
borderBottomWidth: 1,
marginBottom: 15,
paddingVertical: 4,
paddingHorizontal: 2,
},
})
最好不要将内部和外部样式结合起来。
【问题讨论】:
标签: css reactjs react-native tsx react-native-stylesheet