How to change props of a component which I also receive as prop?

Viewed 22

Let's say I have a component Parent

const Parent = () => {
 return (
  <>
   <ChildComponent icon={<Icon/>} />
  </>
)
};

And a component Child

const Child = ({ icon }) => {
 return (
 <>
  {icon}
 </>
)
} 

How do can I change the props for Icon, inside my Child component? I want to dynamically change the color of the icon, and that's done with a color prop on the Icon

1 Answers

You could try this:

const Parent = () => {
  return (
    <>
      <ChildComponent Icon={Icon} />
    </>
  )
};

const Child = ({ Icon }) => {
  const props = {}
  return (
    <>
      <Icon {...props}/>
    </>
  )
}

Related