Last active
November 27, 2020 20:37
-
-
Save DoctorDerek/c3bfdcf82a157058e262417954f77d6a to your computer and use it in GitHub Desktop.
ParentComponentNoSpread.jsx - How to Pass All Props to a Child Component in React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import DisplayAllProps from "./DisplayAllProps" | |
import ChildComponent from "./ChildComponent" | |
const ParentComponent = (props) => ( | |
<section> | |
<h1>ParentComponent's props:</h1> | |
<DisplayAllProps | |
name={props.name} | |
job={props.job} | |
children={props.children} | |
></DisplayAllProps> | |
{/* Both methods to pass children are equivalent */} | |
<ChildComponent name={props.name} job={props.job}> | |
{props.children} | |
</ChildComponent> | |
</section> | |
) | |
export default ParentComponent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment