Grokking React Native
Vote

0% completed

​

Passing Props to Components

Passing a prop looks like writing an attribute on a tag. You add name="value" to the component where you use it, and the component receives that value in one object, usually called props.

From Attributes to the Props Object

The App component is the parent here, and UserProfile is the child. We added a console.log to see exactly what the child receives.

import { View, Text } from 'react-native'; const UserProfile = (props) => { console.log(props); return ( <View> <Text>Name: {props.name}</Text> <Text>Age: {props.age}</Text>

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content