Props
- App is the parent component
- AppChild is the child component called from App
- props is to pass the data from parent to child component.
Â
import React from "react";
const App = () => {
return (
<>
>
);
};
const Child = (props) => {
return (
- {props.id}
- {props.name}
);
};
export default App;
Props - Destructuring
- id and name has to be exactly the same
- if you make this as below it wont work
- let { id1, name1 } = props;
import React from "react";
const App = () => {
return (
<>
>
);
};
const AppChild = (props) => {
let { id, name } = props;
return (
- {id}
- {name}
);
};
export default App;
Slight Variant
- const AppChild = ({ id, name }) =>Â
- Destructuring is done right inside the parantheses of child component
import React from "react";
const App = () => {
return (
<>
>
);
};
const AppChild = ({ id, name }) => {
return (
- {id}
- {name}
);
};
export default App;