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

321
Views
Reaccionar: la mejor manera de pasar atributos html como accesorios

Por ejemplo, quiero comportar un botón como un botón normal y mejorar el componente.

 <Button type="submit" className="btn">Click me!</Button>

conduce a un elemento html:

 <button type="submit" className="btn">Click me!</button>

¿Hay alguna manera de escribir el componente Button de esta manera?:

 const Button = ({children, ...htmlAttributesOnly}) => ( <button {...htmlAttributesOnly}>{children}</button> )

La idea detrás es hacer que un componente sea lo más flexible posible dando acceso a todos los atributos de sus elementos html. ¿O tengo que repetir cada atributo de elemento html?

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

0

Estabas muy cerca de una respuesta, solo envuelve tus accesorios entre llaves:

 const Button = ({ children, ...rest }) => ( <button {...rest}>{children}</button> )
about 4 years ago · Juan Pablo Isaza Report

0

Puede crear un componente de botón como este.

 export default function Button(props) { return <button {...props}>{props.children}</button>; }

Más tarde puedes usarlo así.

 <Button onClick={()=>alert("hello")} style={{padding:10,border:'none',backgroundColor:'white'}} >Click Me</Button>
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!