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

201
Views
Reaccionar: ¿Cómo hacer que un controlador onClick en los padres afecte a los niños?

Originalmente tenía un componente principal que tenía este componente contenedor en algunos elementos DOM:

 const Card = ({ }) => { const LinkComponent = ({ children }) => to && !onClick ? ( <Link aria-label={`${title} ${t('thumbnail-image')}`} to={to}> {children} </Link> ) : ( <a aria-label={`${title} ${t('thumbnail-image')}`} href={href} onClick={onLinkClick}> {children} </a> ); return ( <CardArticle id={id} isListView={isListView} data-testid="card-article"> {showThumbnail && ( <LinkComponent> <CardImage id={id} alt={title} image={image} isLazyLoading={isLazyLoading} isListView={isListView} /> </LinkComponent> )} <CardInfo> <TitleWrapper> <LinkComponent> <CardTitle data-testid="card-title" tabIndex={0} aria-label={title || t('untitled')}> {title} </CardTitle> </LinkComponent> </TitleWrapper> </CardArticle> ); };

Lo que quiero es en lugar de envolver estos elementos con un componente, solo me gustaría pasar una función al controlador onClick del padre de los niños.

 const handleOnClick (e) => { if (to && !onClick) { return <Link aria-label={`${title} ${t('thumbnail-image')}`} to={to}> {xxxxxx} // what goes here? </Link> } else { return <a aria-label={`${title} ${t('thumbnail-image')}`} href={href} onClick={onLinkClick}> {xxxxxx} // what goes here? </a> } } return ( <CardArticle onClick={handleOnClick}> </CardArticle/>

¡Necesito hacer que todo el componente sea un enlace en lugar de secciones como era!

¡Cualquier ayuda sería apreciada!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

si puede editar el componente CardArticle, puede hacerlo de la siguiente manera:

 // CardArticle file const CardArticle = ({children, onClick}) => { return onClick ? onClick(children) : children }
 const Card = ({ }) => { const handleOnClick = (children) => { if (to && !onClick) { return <Link aria-label={`${title} ${t('thumbnail-image')}`} to={to}> {children} // what goes here? </Link> } else { return <a aria-label={`${title} ${t('thumbnail-image')}`} href={href} onClick={onLinkClick}> {children} // what goes here? </a> } } return ( <CardArticle onClick={handleOnClick}> </CardArticle> ) }
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!