Skip to content

Commit 03741ca

Browse files
authored
Merge pull request #255 from chetannada/question218-fix
Detailed Answer added with example in Question 218
2 parents 55f906e + 0057256 commit 03741ca

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
@@ -4937,13 +4937,25 @@
49374937
49384938
218. ### How to pass numbers to React component?
49394939
4940-
You should be passing the numbers via curly braces({}) where as strings in quotes
4940+
We can pass `numbers` as `props` to React component using curly braces `{}` where as `strings` in double quotes `""` or single quotes `''`
49414941
49424942
```jsx
4943-
React.render(
4944-
<User age={30} department={"IT"} />,
4945-
document.getElementById("container")
4946-
);
4943+
import React from "react";
4944+
const ChildComponent = ({ name, age }) => {
4945+
return (
4946+
<>
4947+
My Name is {name} and Age is {age}
4948+
</>
4949+
);
4950+
};
4951+
const ParentComponent = () => {
4952+
return (
4953+
<>
4954+
<ChildComponent name="Chetan" age={30} />
4955+
</>
4956+
);
4957+
};
4958+
export default ParentComponent;
49474959
```
49484960
49494961
**[⬆ Back to Top](#table-of-contents)**

0 commit comments

Comments
 (0)