What's the point if id doesn't work

Tell us what’s happening:
Ok, so I had no problem typing what i was told, but why if I change the value to something other than a number, does it still work?

In other words, why is it WORKING when it SHOULDN’T ? otherwise, what is the point of checking PropTypes, if they are just used anyways?

  **Your code so far**

const Items = (props) => {
return <h1>Current Quantity of: {props.quantity}</h1>
// Change code below this line
Items.propTypes = {quantity: PropTypes.number.isRequired } 
// Change code above this line
Items.defaultProps = {
quantity: 0
class ShoppingCart extends React.Component {
constructor(props) {
render() {
  return <Items quantity={"1"}/>
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Use PropTypes to Define the Props You Expect

Link to the challenge:

just incase i need to point it out, the quantity is being passed as a string instead of a number… so it shouldn’t be accepted. Should it?

One other resource suggested this is because the production, not the development, version of react is being used… i’m not sure if that’s the case, but regardless, why wouldn’t the production version reject it? especially if, ultimately, the source could be an external API?

It will only show warning in console

PropTypes exports a range of validators that can be used to make sure the data you receive is valid. In this example, we’re using PropTypes.string . When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. For performance reasons, propTypes is only checked in development mode.

That’s unfortunately a limitations of interpreted language, ultimately they will still compile.

That’s why superset of JS like Typescript are more and more popular nowadays.
It has also great support for react.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.