Props in React JS
Props are used to pass data from a parent component to a child component. Here's an example of a parent component that passes props to a child component:
jsx
function App() {
return (
<div>
<Greeting name="John" />
</div>
);
}
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
In this example, the App component passes a prop name to the Greeting component.
No comments:
Post a Comment