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

101
Views
Default Props not Working in React Native

I created a reusable component for SvgIcon in react-native. I passed three props in it namely, icon, width and height. I also setup some default props in my component. The issue is that my component is picking default prop for icon but it is not picking default props for width and height. When I am passing width and height as props in my SvgIcon component, it is taking those props, but what I want is that I don't need to pass width and height props every single time. The width and height must be 24 by default.

import React from "react";
import PropTypes from "prop-types";
import defaultSvg from "@app/assets/svgs/check-logo-sm.svg";

const SvgIcon = ({ width, height, icon: Icon }) => {
  return <Icon width={width} height={height} />;
};

SvgIcon.defaultProps = {
  width: 24,
  height: 24,
  icon: defaultSvg,
};

export default SvgIcon;

SvgIcon.propTypes = {
  width: PropTypes.number,
  height: PropTypes.number,
  icon: PropTypes.func,
};

When I call the component as <SvgIcon icon={homeIcon} width={40} height={40} />, it works fine, but I want to call it as <SvgIcon icon={homeIcon} />, and want it to take its default width and height.

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

0

Use destructirization in props { width = 50, height = 50, icon }

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!