26
loading...
This website collects cookies to deliver better user experience
/* Generic Row that doesn’t know about its children */
const GenericRow = (props) => (
<View {...props}>
/* Left column or Left child */
<View style={styles.column}>{props.left}</View>
/* Right column or Right child */
<View style={styles.column}>{props.right}</View>
</View>
);
/**
* Specialization of our Generic Row
* This component is going to be used when it’s known that left and right are texts
**/
const CustomRow = ({ left, right, ...props }) => (
<Generic
{ ...props }
/* Left child */
left = { <Text>{left?.toString()}</Text> }
/* Right Child */
right = { <Text>{right?.toString()}</Text> }
/>
);
/* Child of CustomRow | First Row */
const NameRow = (props) => (
<CustomRow left="Developer’s Name" right="Shivam Gupta" />
);
/* Second Row for the age */
const AgeRow = (props) => <CustomRow left="Age" right="22" />;
/* Action: Connect | Third row */
const ConnectActionRow = (props) => (
/* Notice Generic Row not a CustomRow! */
<GenericRow left = { <Text>Connect</Text> } right = {<Button title="Hit me!" />} />
);
const Error = ({ children, fontFamily, style }) => (
/* User may overwrite the color, or fontWeight using his own style. */
<Text
style={[
{ color: “red”, fontWeight: "bold" },
/* Notice this written after the our style, letting user to overwrite color and fontWeight. */
{ ...style}
]}
>{children}</Text>
);
“At Facebook, we use React in thousands of components, and we haven’t found any use cases where we would recommend creating component inheritance hierarchies.”