Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
How to pass props to a children object? children will only have a button or a text
export const PopOver = ({
  children, -----------------------------------------> I get children
  headerText,
  bodyText,
  hasHeader,
  hasBody,
  hasFooter,
  cancelButtonText,
  okButtonText,
  hasCloseButton,
  onOkPress,
  onCancelPress,
  ...rest
}: PopoverProps): JSX.Element => {
  return (
    <Popover
      trigger={(triggerProps) => {
        return <Button {...triggerProps}>Trigger</Button>; //How do I pass trigger props to the children I get???
      }}
      {...rest}
    >

In the code I have mentioned above, I want to return children (this.props.children) instead of the button to make it more generic. something to the equivalent of:

return (
    <Popover
      trigger={(triggerProps) => {
        return <child {...triggerProps}>Trigger</child>;
      }}
      {...rest}
    >
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this:

<Popover
  trigger={triggerProps => 
    React.Children.map(children, child =>
      React.isValidElement(child) 
        ? React.cloneElement(child, { ...triggerProps }) 
        : child
    )
  }
  {...rest}
/>

References:

https://reactjs.org/docs/react-api.html#reactchildren

https://reactjs.org/docs/react-api.html#cloneelement

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!