Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Destructing an object and using it – React prop

I have a React component that receives a prop, 2 values should be destructed from the prop and the prop itself should be passed further, I tried the following but am receiving a Line 23:3: Duplicate key 'countryData' no-dupe-keys warning.

const IndividualCountryContainer = ({
  countryData: {
    name: { common },
    flags: { png },
  },
  countryData
}) => (
  <div className='country'>
    <img className='country-flag' src={png} alt={`${common}'s flag`} />
    <IndividualCountryData countryData={countryData} />
  </div>
);

So, how do I solve this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Destructure your prop inside your function definition, like:

const IndividualCountryContainer = ({ countryData }) => {
  const {
    name: { common },
    flags: { png },
  } = countryData;

  return (
    <div className="country">
      <img className="country-flag" src={png} alt={`${common}'s flag`} />
      <IndividualCountryData countryData={countryData} />
    </div>
  );
};

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading