Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Passing components as children in react

const UserCard = ({ name, children }) => {
  return (
    <div>
      <p>Name: {name}</p>
      {children}
    </div>
  )
}

const UserIcon = ({ profilePic }) => {
  return <img src={profilePic} alt="profile" />
}

function App() {
  return (
    <div>
      <UserCard name="Ranjeet">
        <UserIcon profilePic="image.jpg" />
      </UserCard>
    </div>
  )
}

export default App
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Passing #components #children #react
ADD COMMENT
Topic
Name
5+7 =