Skip to content

Commit 0057256

Browse files
committed
Detailed Answer added with example in Question 218
1 parent 5b24cd3 commit 0057256

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

README.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -4917,13 +4917,25 @@
49174917
49184918
218. ### How to pass numbers to React component?
49194919
4920-
You should be passing the numbers via curly braces({}) where as strings in quotes
4920+
We can pass `numbers` as `props` to React component using curly braces `{}` where as `strings` in double quotes `""` or single quotes `''`
49214921
49224922
```jsx
4923-
React.render(
4924-
<User age={30} department={"IT"} />,
4925-
document.getElementById("container")
4926-
);
4923+
import React from "react";
4924+
const ChildComponent = ({ name, age }) => {
4925+
return (
4926+
<>
4927+
My Name is {name} and Age is {age}
4928+
</>
4929+
);
4930+
};
4931+
const ParentComponent = () => {
4932+
return (
4933+
<>
4934+
<ChildComponent name="Chetan" age={30} />
4935+
</>
4936+
);
4937+
};
4938+
export default ParentComponent;
49274939
```
49284940
49294941
**[⬆ Back to Top](#table-of-contents)**

0 commit comments

Comments
 (0)