File tree 1 file changed +17
-5
lines changed
1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 4937
4937
4938
4938
218. ### How to pass numbers to React component?
4939
4939
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 ` ' ' `
4941
4941
4942
4942
```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;
4947
4959
```
4948
4960
4949
4961
**[⬆ Back to Top](#table-of-contents)**
You can’t perform that action at this time.
0 commit comments