Reagieren Native: was ist der richtige Weg, um pass-Stil Requisiten, bei Verwendung von spread-operator auf die Kind-Komponente

Dies ist mein Komponente A:

const GenericTextInput = (props) => {
  return (
      <TextInput
        style={styles.input}
        {...props}
      />
  );
};

Dies ist mein Komponente 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>
   );
};

Möchte ich hinzufügen, dass ein bestimmtes styling zum 2. GenericTextInput in meinem Komponente B. In der Komponente A ich will das spread operator (es ist so bequem).

Wenn ich einfach machen:

//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>
       );
    };

Werde ich haben 2 style props im comp. Ein, und die zweite style prop wird komplett überschreibt die erste.

Was ist die richtige Art und Weise zum hinzufügen einer spezifischen styling für die 2.GenericTextInput?

InformationsquelleAutor Edgar | 2016-11-17
Schreibe einen Kommentar