What are props in React Native?
What are props in React Native?
Props in React Native, short for properties, are a fundamental concept used to pass data from one component to another. They allow components to be customized and reused with different data. Here’s a detailed explanation:
Props are immutable data that are passed from a parent component to a child component. They are used to configure a component and control its behavior or appearance. Unlike state, which is managed within a component, props are managed outside the component and passed down the component tree.
When a parent component renders a child component, it can pass data to the child component through props. The child component receives these props as an argument in its function or as a property in its class.
For example, consider a simple Greeting
component that takes a name
prop:
// Parent Component
export default function App() {
return (
<View>
<Greeting name="John" />
<Greeting name="Jane" />
</View>
);
}
// Child Component
function Greeting(props) {
return <Text>Hello, {props.name}!</Text>;
}
In this example, the App
component passes the name
prop to the Greeting
component, which then uses it to display a personalized greeting.
Here’s a more detailed...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào