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

113
Views
React.js: ¿Cómo puedo descargar dos archivos diferentes con dos componentes diferentes de botones separados?

Tengo dos botones como componentes que necesitan descargar dos archivos diferentes, pero hasta ahora ambos botones descargan el mismo archivo, lo que no me sorprende. He probado diferentes soluciones, con useState() y sin ella, pero ninguna de ellas parece funcionar. Sé que me falta lógica aquí, pero no entiendo dónde me falta. ¿Cómo descargo un archivo diferente al hacer clic en el primer botón y descargo otro archivo al hacer clic en otro botón? ¿Debería haber algo que deba recapitular también?

Aquí está el código:

Hero.js (componente principal)

 import Button from "../../components/UI/Button/Button"; const Hero = () => { return ( <div> <div> <Button>CV (English)</Button> <Button>CV (Another Language)</Button> </div> </div> ); }; export default Hero;

Button.js (componente secundario)

 import cv from "../../../assets/files/CV English.pdf"; import anotherLanguage from "../../../assets/files/anotherLanguage.pdf"; const Button = (props) => { const file = cv; return ( <button> {file === cv ? ( <a href={cv} download="CV English"> {props.children} </a> ) : ( <a href={anotherLanguage} download="CV Another Language"> {props.children} </a> )} </button> ); }; export default Button;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías pasar un accesorio de idioma al botón como este:

 <div> <Button language="en">CV (English)</Button> <Button>CV (Another Language)</Button> </div>

Y luego utilícelo en el componente Botón de esta manera:

 import cv from "../../../assets/files/CV English.pdf"; import anotherLanguage from "../../../assets/files/anotherLanguage.pdf"; const Button = (props) => { const file = cv; return ( <button> {props.language === "en" ? ( <a href={cv} download="CV English"> {props.children} </a> ) : ( <a href={anotherLanguage} download="CV Another Language"> {props.children} </a> )} </button> ); }; export default 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!