上採用擴展操作時,這是我的成分A:陣營母語:什麼是傳遞風格的道具有道,子組件
const GenericTextInput = (props) => {
return (
<TextInput
style={styles.input}
{...props}
/>
);
};
這是我成分B:
const SignIn = (props) => {
return (
<View>
<GenericTextInput
placeholder="Email"
autoFocus={true}
keyboardType="email-address"
returnKeyType="next"
autoCorrect={false}
placeholderTextColor='rgba(250,248,244, .4)'
underlineColorAndroid='rgba(250,248,244, .7)'
/>
<GenericTextInput
placeholder="Password"
placeholderTextColor='rgba(250,248,244, .4)'
underlineColorAndroid='rgba(250,248,244, .7)'
secureTextEntry={true}
/>
</View>
);
};
我想添加一個特定的樣式到我的組件B中的第二個GenericTextInput
。在組件A我想使用spread operator
(這很方便)。
如果我只是做:
//component A
const GenericTextInput = (props) => {
return (
<TextInput
style={[styles.input, props.styles]}
{...props}
/>
);
};
//component B
const SignIn = (props) => {
return (
<View>
<GenericTextInput
placeholder="Email"
autoFocus={true}
keyboardType="email-address"
returnKeyType="next"
autoCorrect={false}
placeholderTextColor='rgba(250,248,244, .4)'
underlineColorAndroid='rgba(250,248,244, .7)'
/>
<GenericTextInput
placeholder="Password"
placeholderTextColor='rgba(250,248,244, .4)'
underlineColorAndroid='rgba(250,248,244, .7)'
secureTextEntry={true}
style={styles.customStyleForSecondInput}
/>
</View>
);
};
我有2個style
props
在補償。 A,第二個style
prop
將完全覆蓋第一個。
將特定樣式添加到第二個GenericTextInput
的正確方法是什麼?
謝謝!我不知道這樣的解構是可能的:{foo,... bar} = obj – Edgar
@Edgar我爲這個後代增加了一些關於這個語法的更多細節。 – jevakallio