-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
React and React Native - Fifth Edition
By :
In React, component properties, commonly known as props, allow us to pass data from a parent component to its child components. Props provide a way to customize and configure components, making them flexible and reusable. Props are read-only, meaning that the child component should not modify them directly. Instead, the parent component can update the props value and trigger a re-render of the child component with the updated data.
When defining a function component, you can access the props passed to it as a parameter:
const MyComponent = (props) => {
return (
<div>
<h1>{props.title}</h1>
<p>{props.description}</p>
</div>
);
};
In the above example, the MyComponent function component receives the props object as a parameter. We can access the individual props by using dot notation, such as props.title and props.description, to render the data within the component’s JSX...
Change the font size
Change margin width
Change background colour