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

169
Views
Prop value fallback with react and prop-types

I am new to prop validation in React. Let's say that I have the following code, where the validation is focused on the title prop as a string

import PropTypes from "prop-types";
function Component (props) {
    [...]
}
Component.propTypes = {
    title: PropTypes.string
}
Component.defaultProps = {
    title: 'Foo'
}

If the value of the title prop happens to be a number instead, the component will continue its lifecycle with the wrong prop, just after throwing a Warning in the console.

Is there a built in way or a workaround to make that invalid prop get a fallback value or simply the default value?

about 4 years ago · Juan Pablo Isaza
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!