2

I have the following case:

 <ComponentA render={({propA, propB, propC}) => (
          <ComponentB
              propA={propA}
              propB={propB}
              propC={propC}
           />
 )}/>

In my real project, I have many more properties I want transmit to ComponentB. Is there a way to say "take all properties"?

I would like to have a shortcut to this so I don't have to copy paste all the attributes in this style. This seems like a very bad and unnecessary way of giving properties to a component.

yemerra
  • 1,352
  • 4
  • 19
  • 44

2 Answers2

3

Use the spread operator:

const MyComponent = ({destructuredProp, ...rest}) =>{
    return(
        <>
            <ChildA value={destructuredProp} />
            <ChildB {...rest} />
       </> 
   )
}
Dupocas
  • 20,285
  • 6
  • 38
  • 56
2

Instead of destructuring the input you can use the spread operator

 <ComponentA render={(props) => (
          <ComponentB {...props} />
 )}/>
Auskennfuchs
  • 1,577
  • 9
  • 18