I cant understand why styling is not being applied to the {props.children}
inside view in the following code. Its not throwing any errors but only renders the {props.children}
as simply text.
import React from 'react';
import { View } from 'react-native';
const Card = (props) => {
return (
<View style={styles.containerStyle}>
{props.children}
</View>
);
};
const styles = {
containerStyle: {
borderWidth: 8,
borderRadius: 2,
borderColor: 'black',
borderBottomWidth: 0,
shadowColor: 'black',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.1,
shadowRadius: 2,
elevation: 1,
marginLeft: 5,
marginRight: 5,
marginTop: 60
}
};
export default Card;
render {props.children}
here:
import React from 'react';
import { Text } from 'react-native';
import Card from './Card';
const AlbumDetail = (props) => (
<Card>
<Text>{props.album.title}</Text>
</Card>
);
export default AlbumDetail;
@Murmeltier's answer has tiny error.
Text component has the name of property, 'style', not 'styles'.
<Text style={props.album.title}></Text>
You are just passing your nested components to your AlbumDetail
but you are not applying any style to the text
inside of your Card
-component. You should set them like this:
import React from 'react';
import { Text } from 'react-native';
import Card from './Card';
const AlbumDetail = (props) => (
<Card>
<Text styles={props.album.title}></Text>
</Card>
);
export default AlbumDetail;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With