Props (short for properties) are used to pass data from one component to another in React Native. They make components reusable, dynamic, and configurable.
props objectProps are passed to a component as attributes and received as a parameter.
// Passing props to a component
<MyComponent title="Hello World" />
// Child component receiving props
import React from "react";
import { Text, View } from "react-native";
const Greeting = (props) => {
return (
<View>
<Text>Hello {props.name}</Text>
</View>
);
};
export default Greeting;
// Parent component passing props
import React from "react";
import { View } from "react-native";
import Greeting from "./Greeting";
const App = () => {
return (
<View>
<Greeting name="Meghraj" />
</View>
);
};
export default App;
The screen will display:
Hello Meghraj
The value "Meghraj" is passed from the parent component to the child using props.
Simulate passing props! Edit the inputs below (Parent) to see how the component (Child) updates instantly.
<Card name="React Native" icon="?" />UserCard componentname and age as props