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

117
Views
React.js: How can I download two different files with two different separate Button components?

I have got two buttons as components that need to download two different files, but so far both buttons download the same file that is no surprise for me. I have tried different solutions, with useState() and without, but none of them seem to be working. I know I am missing logic here, but I do not understand where I am missing it. How do I download a different file when clicking the first button, and download another file when clicking on another button? Should there be something that I should recap on, too?

Here is the code:

Hero.js (Parent component)

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 (Child component)

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

You could pass a language prop to the button like this:

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

And then use it in the Button component like this:

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!