Skip to content

Instantly share code, notes, and snippets.

@DoctorDerek
Last active November 27, 2020 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DoctorDerek/c3bfdcf82a157058e262417954f77d6a to your computer and use it in GitHub Desktop.
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
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