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 4917
4917
4918
4918
218. ### How to pass numbers to React component?
4919
4919
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 ` ' ' `
4921
4921
4922
4922
```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;
4927
4939
```
4928
4940
4929
4941
**[⬆ Back to Top](#table-of-contents)**
You can’t perform that action at this time.
0 commit comments