Home > Software design >  React native passing multiple styles from parent to child, which method is more used? what is the di
React native passing multiple styles from parent to child, which method is more used? what is the di

Time:01-18

React native passing multiple styles from parent to child, component, which method is more used? What is the difference?

Rest parameter type, <Text style={{...styles.title, ...props.style}}>{props.children}

I also found this syntax here:

using array, <Text style={[styles.title, props.style]}>{props.children}

CodePudding user response:

There are no differences between the two examples. However, the second way is the standard way to combine styles as mentioned in the react-native documentation.

The style prop can be a plain old JavaScript object. That's what we usually use for example code. You can also pass an array of styles - the last style in the array has precedence, so you can use this to inherit styles.

  •  Tags:  
  • Related