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

303
Views
React FC - Is declaring props as optional with an undefined default/fallback value considered superfluous?

Imagine this component

function AudioPlayer({
   uri,
   volume = 1.0,
   onPlay = undefined <--- superfluous?
}) {

}

AudioPlayer.propTypes = {
   uri: PropTypes.string.isRequired,
   volume: PropTypes.number,
   onPlay: PropTypes.func,
}

As you can see, onPlay is optional (as declared in the prop-types), but... is it correct (I mean, not superfluous) to set it as onPlay = undefined?

Or should I just do:

function AudioPlayer({
   uri,
   volume = 1.0,
   onPlay,
}) {

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

0

In these type of situations, I don't declare it at all. If I want to declare it just to show that this will exist in future, I assign a default value type of what it will be. Like 0 for number, or empty string for type of string etc.

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!